finding the row number of a matrix

1 Ansicht (letzte 30 Tage)
Mnr
Mnr am 24 Nov. 2015
Kommentiert: Mnr am 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!

Akzeptierte Antwort

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

Weitere Antworten (0)

Kategorien

Mehr zu Resizing and Reshaping Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by