Vector matrix multiplication with a condition
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Madhubhashi Bamunuarachchi
am 30 Jan. 2019
Kommentiert: Madhubhashi Bamunuarachchi
am 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 Kommentare
Akzeptierte Antwort
James Tursa
am 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);
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Creating and Concatenating 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!