Effacer les filtres
Effacer les filtres

finding the row number of a matrix

1 vue (au cours des 30 derniers jours)
Mnr
Mnr le 24 Nov 2015
Commenté : Mnr le 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!

Réponse acceptée

Andrei Bobrov
Andrei Bobrov le 24 Nov 2015
[log1,idxb] = ismember(A,B,'rows');
  1 commentaire
Mnr
Mnr le 24 Nov 2015
Thank you!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Resizing and Reshaping Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by