finding the row number of a matrix

1 view (last 30 days)
Mnr
Mnr on 24 Nov 2015
Commented: Mnr on 24 Nov 2015
Hello there,
I have two matrices one A with size MxN and the other one B with size KxN, and rows of B are taken from rows of A. For each row of B, I would like to find the corresponding row in A and store its row number. For instance, let A be:[ -1 -1 -1 -1;-1 -1 -1 1;-1 -1 1 -1;-1 -1 1 1;-1 1 -1 -1;-1 1 -1 1;-1 1 1 -1;-1 1 1 1;1 -1 -1 -1;1 -1 -1 1;1 -1 1 -1;1 -1 1 1;1 1 -1 -1;1 1 -1 1;1 1 1 -1;1 1 1 1]; and B is [-1 1 1 1;1 1 -1 -1;-1 1 1 -1;1 -1 -1 -1;1 1 1 -1;1 1 -1 -1;1 -1 1 1;-1 1 1 1;-1 1 -1 1;-1 1 -1 1;1 1 1 -1;-1 1 -1 1;-1 -1 -1 1;1 -1 1 1;-1 -1 1 1; 1 1 1 1;1 1 1 1;1 1 -1 -1;1 -1 -1 1;1 1 -1 1;1 1 -1 -1;1 1 -1 -1;1 -1 1 1;-1 -1 -1 1]. I would like to compare each row of B with rows of A and see to which of them is equal. That is, row 1 in B in this example is the same as row 8 in A. Could you help me with a fast way of doing this task? Thank you!

Accepted Answer

Andrei Bobrov
Andrei Bobrov on 24 Nov 2015
[log1,idxb] = ismember(A,B,'rows');

More Answers (0)

Categories

Find more on Resizing and Reshaping Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!