Finding corresponding rows in two matrices

1 view (last 30 days)
Hi Everyone,
I have two different 50x20 matrices which are meant to represent 50 objects with 20 properties each.
Without many for loops and if-statements, is there a simple way to find the row in Matrix2 (if any) that corresponds to the same row in Matrix1? As a simple example:
desc1 = zeros(50,20);
desc2 = zeros(50,20);
% Create a unique row we can find
desc1(5,15) = 39;
desc2(19, 15) = 39;
Ideally what I'd like to do is call some built in function F on desc1 and desc2 such that:
F(desc1(5,:), desc2) = 19
Because the element in the 19th row of desc2 is the same as desc1. If there are more than one row of the same entry, I'd like to get a vector with all of them.
Any ideas?
Thanks.

Accepted Answer

Andrei Bobrov
Andrei Bobrov on 5 Jun 2012
[i1,i1] = ismember(desc1(5,:),desc2,'rows')

More Answers (0)

Community Treasure Hunt

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

Start Hunting!