How to add values from array A (n,3) to array B(m,2)based on values equality between m and n?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
YAAQOB AL-JAMALI
am 21 Jul. 2023
Kommentiert: Dyuman Joshi
am 26 Jul. 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 Kommentare
Akzeptierte Antwort
Dyuman Joshi
am 21 Jul. 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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!