Hi, i have several matrices that has 3 columns each, but the number of rows is not equal. im trying to find a fast way of comparing the first two columns in all 3 matrices and to find the rows (column 1 and 2) that are identical in all 3 of them. i've tried "ismember", it works ok but when dealing with lots of matrices its too slow.
can anyone recomend a different function? thank you for your help.

댓글 수: 3

the cyclist
the cyclist 2014년 2월 11일
Can you post an example of your code, as well as some sample input/output that you expect? This will save a lot of guesswork on our part.
Dany
Dany 2014년 2월 11일
편집: the cyclist 2014년 2월 11일
a=[1,2,3;
1,3,5;
2,5,7];
b=[1,2,6;
1,4,8;
2,5,8];
c=[1,4,7;
1,5,3;
2,5,9];
those three matrices have only one row (column 1 and 2) in common. the third one ...... thats basicaly what i want, the index of the common rows in all matrices.
thankyou sir i have one doubt in my coding.how to remove a duplicate matrices in the set of all matrices.

댓글을 달려면 로그인하십시오.

 채택된 답변

the cyclist
the cyclist 2014년 2월 11일
편집: the cyclist 2014년 2월 11일

0 개 추천

I think your best bet for something fast is the intersect() command.
doc intersect
for details. Be sure to use the "rows" argument.
Here is some code that I believe will do what you want, but I have to admit I did not test much:
a=[1,2,3;
1,3,5;
2,5,7];
b=[1,2,6;
1,4,8;
2,5,8];
c=[1,4,7;
1,5,3;
2,5,9];
[ab,ia,ib] = intersect(a(:,1:2),b(:,1:2),'rows')
[abc,iab,ic] = intersect(ab(:,1:2),c(:,1:2),'rows')
a_row_idx = ia(iab)
b_row_idx = ib(iab)
c_row_idx = ic

추가 답변 (2개)

Jos (10584)
Jos (10584) 2014년 2월 11일

0 개 추천

INTERSECT or ISMEMBER come into mind:
tf = ismember(C, A(ismember(A,B,'rows')), 'rows')
result = C(tf,:)
Dany
Dany 2014년 2월 11일

0 개 추천

thank you. i will try the "intersect" command.
is it possible to put several commads of "ismember" one into another? can those functions work on several matrices at once? more then two?

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품

질문:

2014년 2월 11일

댓글:

2015년 4월 24일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by