|MATLAB Function Reference|
Test for any nonzeros
B = any(A)
tests whether any of the elements along various dimensions of an array are nonzero or logical true (
A is a vector,
any(A) returns logical true (
1) if any of the elements of
A are nonzero, and returns logical false (
0) if all the elements are zero.
A is a matrix,
any(A) treats the columns of
A as vectors, returning a row vector of
A is a multidimensional array,
any(A) treats the values along the first non-singleton dimension as vectors, returning a logical condition for each vector.
B = any(A, tests along the dimension of
A specified by scalar
B = (A < 0.5) returns logical true (
1) only where
A is less than one half:
any function reduces such a vector of logical conditions to a single condition. In this case, any(B) yields
any particularly useful in
where code is executed depending on a single condition, not a vector of possibly conflicting conditions.
any function twice to a matrix, as in
any(any(A)), always reduces it to a scalar condition.
all, logical operators, relational operators,
Other functions that collapse an array's dimensions include: