How can I compare two matrices of different dimensions without looping?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
MRC
le 27 Nov 2013
Modifié(e) : Azzi Abdelmalek
le 27 Nov 2013
Hi, I have two matrices of different dimensions. For example:
A=[1 1 1 1; 2 1 1 1; 2 0 0 0; 3 0 1 0; 3 0 0 0; 3 0 0 1; 4 1 1 1; 5 1 0 1; 5 1 1 1; 5 0 0 1];
B=[3 0 1 0; 3 0 0 1; 5 1 0 1; 5 0 0 1];
I want to obtain a vector C of dimension size(A,1)x 1 with C(i) equal to 1 if A(i,:) is equal to at least one row of B and 0 otherwise. I cannot use loops because in practice matrices A and B have very high dimensions. In this particular example, I should get:
C=[0; 0; 0; 1; 0; 1; 0; 1; 0; 1];
Thanks!
0 commentaires
Réponse acceptée
Azzi Abdelmalek
le 27 Nov 2013
Modifié(e) : Azzi Abdelmalek
le 27 Nov 2013
C=ismember(A,B,'rows')
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements 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!