How to add values from array A (n,3) to array B(m,2)based on values equality between m and n?
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
YAAQOB AL-JAMALI
il 21 Lug 2023
Commentato: Dyuman Joshi
il 26 Lug 2023
I have two arrays A and B of different sizes, wherein, array B is a subarray from array A. Therefore, I want to pad the array B with values from the third colums of array A(:,3) based on the equality comparison of B(ii,1) and A(ii,1).Resulted array should be B(m,3)
I have attached examples of dataset for the 2 arrays A and B namely pathInfo,and pathReduced respectively.
0 Commenti
Risposta accettata
Dyuman Joshi
il 21 Lug 2023
You can directly get the desired result -
load('pathReduced.mat')
load('pathInfo.mat')
pathReduced
inpath
%Check which elements in the 1st column of inpath are common to the
%elements in the 1st column of pathReduced
idx = ismember(inpath(:,1),pathReduced(:,1));
%Get the sub array from inpath (as pathReduced is sub array of inpath as
%mentioned in the problem above)
out = inpath(idx,:)
2 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Matrix Indexing in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!