MATLAB: OR, Matrices and equality

MATLABmatrixor

M=[0 1 0];
w=M==[1 1 0] | Μ==[1 1 1]
w =
1 1 1
I wanted to get a resuilt that show this statemant is wrong. Can somebody explane why that didn't happen?

Best Answer

The == and | operations you are doing are element-wise operations, so you get an element-wise result according to the precedence of the operators. To do what you appear to want to do, compare as entire rows, you could do this:
w = ismember(M,[1 1 0;1 1 1],'rows');
Or in a more verbose fashion,
w = isequal(M,[1 1 0]) || isequal(M,[1 1 1]);