MATLAB: Vector matrix multiplication with a condition

conditionalmatrixmultiplicationvector

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.

Best Answer

For later versions of MATLAB:
c = all(A==B | A==2,2);
For earlier versions:
c = all(bsxfun(@eq,A,B) | A==2,2);