finding similar rows in matrices
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Dany
am 11 Feb. 2014
Kommentiert: SIVAKUMAR KARURNKARAN
am 24 Apr. 2015
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 Kommentare
SIVAKUMAR KARURNKARAN
am 24 Apr. 2015
thankyou sir i have one doubt in my coding.how to remove a duplicate matrices in the set of all matrices.
Akzeptierte Antwort
the cyclist
am 11 Feb. 2014
Bearbeitet: the cyclist
am 11 Feb. 2014
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
0 Kommentare
Weitere Antworten (2)
Jos (10584)
am 11 Feb. 2014
INTERSECT or ISMEMBER come into mind:
tf = ismember(C, A(ismember(A,B,'rows')), 'rows')
result = C(tf,:)
0 Kommentare
Siehe auch
Kategorien
Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!