Vector matrix multiplication with a condition
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Madhubhashi Bamunuarachchi
le 30 Jan 2019
Commenté : Madhubhashi Bamunuarachchi
le 31 Jan 2019
Hi,
I need to find which rows of A are equal to B and result should be a vector with 1's and 0's (1 for rows that are equal and zero for not equal).
However, A's positions with value 2 should be disregarded in comparison and should not affect the equality check.
A = 1 1 2 0
1 0 1 2
2 2 1 0
B = 1 0 1 1
Can this be done without a for loop as following?
[row,col] = size(A);
for i = 1:row
c(i) = all(A(i,:) == B | A(i,:) == 2);
end
Thank you.
0 commentaires
Réponse acceptée
James Tursa
le 31 Jan 2019
For later versions of MATLAB:
c = all(A==B | A==2,2);
For earlier versions:
c = all(bsxfun(@eq,A,B) | A==2,2);
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Creating and Concatenating 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!