Your problem is that the result of
or
will return a logical matrix the same size as X(:,:,1) which apparently is never all true or all false and thus the if statement always evaluates to be false. The reson is this performs an element-wise comparison. If you want to check equality of the entire matrix, you should use the isequal function (isequaln if you want to ignore NaN in the matrices).
X = randi([0 1],2,2,902);
b=2;
while b < 902
if isequal(X(:,:,1),X(:,:,b))
b
end
b=b+1;
end
disp done
Best Answer