finding the row number of a matrix

1 visualizzazione (ultimi 30 giorni)
Mnr
Mnr il 24 Nov 2015
Commentato: Mnr il 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!

Risposta accettata

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

Più risposte (0)

Categorie

Scopri di più su Resizing and Reshaping Matrices in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by