How to add values from array A (n,3) to array B(m,2)based on values equality between m and n?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
YAAQOB AL-JAMALI
le 21 Juil 2023
Commenté : Dyuman Joshi
le 26 Juil 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 commentaires
Réponse acceptée
Dyuman Joshi
le 21 Juil 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 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Matrices and Arrays dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!