how to compare 3 matrix

10 vues (au cours des 30 derniers jours)
Nejc
Nejc le 22 Mar 2013
Hi
I got 3 matrixes, each different vertical dimension (mx3,nx3,px3). What I need to do is to compare first and second column in all 3 matrixes. If first and second data in a row match in all 3 matrixes, than i have to extract that in new matrix. How I do that.
Here are examples of matrixes:
A=[1 22 501;1 23 224;2 15 6;2 13 221;2 6 14; 3 2 10; 3 12 50];
B=[1 22 5;1 26 33;2 14 10;2 15 13;2 6 14; 3 2 166; 3 12 60; 4 7 12];
C=[1 2 14;1 22 15;2 23 6;2 15 20;2 6 14; 3 2 11; 3 5 100; 3 12 0; 4 7 12;]
The result must come:
D=[1 22; 2 15; 2 6;3 2;3 12]
Thank you very much in advance. Nejc

Réponse acceptée

Azzi Abdelmalek
Azzi Abdelmalek le 22 Mar 2013
Modifié(e) : Azzi Abdelmalek le 22 Mar 2013
a=A(:,1:2)
D=a(ismember(a,B(:,1:2),'rows') & ismember(a,C(:,1:2),'rows') ,:)

Plus de réponses (0)

Catégories

En savoir plus sur Logical 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!

Translated by