merging two datasets based on two identical rows in each data set
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
sensation
le 27 Nov 2019
Commenté : sensation
le 2 Déc 2019
Hi,
I am looking to compare two datasets and rearrange their values:
array A:
A=[1 150 234,
1 151 234,
3 151 180,
5 152 345,
4 160 674]; % i should compare in the same time column A(:,2) and A(:,3) with B(:,1) and B(:,2)
B=[151 234 10,
152 345 11,
160 674 10
151 180 1,
150 234 5];
% Result should be:
C=A=[1 150 234 5,
1 151 234 10,
3 151 180 1,
5 152 345 11,
4 160 674 10];
I tried to use ismember but it takes into account only one column of each dataset. I would like to search two identical columns in set B and then merge all data in C as showed in example.
Thanks a lot!
0 commentaires
Réponse acceptée
JESUS DAVID ARIZA ROYETH
le 27 Nov 2019
solution:
[~,n]=ismember(A(:,2:3),B(:,1:2),'rows')
C=[A B(n,end)]
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Whos 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!