Compare two tables and extract the columns similar to both
8 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Curious Mind
il 6 Nov 2019
Modificato: the cyclist
il 6 Nov 2019
Hi I have two data matrix, one is A and the other is B. I want to compare each column in A to B and if a match is found in B, then the whole column(s) in B should be extracted. In the attached file, under A, 11, 12, 13 and 14 can also be found in B. In this case all the values under 11, 12, 13 and 14 in B are extracted into C.
I tried using intersect but it doens't work.
Thanks!![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/247134/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/247134/image.png)
0 Commenti
Risposta accettata
the cyclist
il 6 Nov 2019
Modificato: the cyclist
il 6 Nov 2019
If I understand correctly, then
C = B(:,ismember(B(1,:),A))
does what you want.
From your example, it looks like A is a row vector, and you want to compare it to the first row of B. That's what this code does.
0 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Logical 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!