One element of the array is required to be null for this test to fail
>> A = rand(100, 3) + 1; >> if A; disp('True'); else disp('False'); end True >> A(35) = 0; >> if A; disp('True'); else disp('False'); end False
If you want to check that the array does not contain only zeros, you can use the any keyword:
>> A = rand(100, 3) + 1; >> A(35) = 0; >> if any(A(:)); disp('True'); else disp('False'); end True >> A = 0 * A; >> if any(A(:)); disp('True'); else disp('False'); end False
Edit:
Sorry, as SCFrench mentions in the comments, use any(A(:)) to check each element in the array, not any(A) - this has been properly edited in my answer above.
source share