MATLAB: Determine all cells are non-zero within a matrix


I am trying to determine if all of the numbers in "x" is non-zero values:
x = [1 1 0]
% 1:
if x ~= [0 0 0]
disp('x is not zeros')
% 2:
if all(x ~= 0)
disp('x is not zeros')
but the output is saying the x is zeros.
what mistake did I make?

Best Answer

  • Your second if statement is correct, and I get the correct output (none).