Skip to content

any

Test whether any element of an array is nonzero.

B = any(A)
B = any(A, dim)
B = any(A, 'all')

Returns logical true (1) if any element of A along the operating dimension is nonzero (or true), false (0) otherwise. With no dimension argument, operates along the first non-singleton dimension. With 'all', reduces every element to a single scalar.

For matrices, any(A) produces a row vector of column-wise any results. NaN counts as nonzero.

any([0 0 0]) % 0
any([0 1 0]) % 1
any([0 0; 0 1]) % [0 1] per-column
any([0 0; 0 1], 'all') % 1
  • all — Test whether all elements of an array are nonzero.
  • sum — Sum elements of an array.

Also categorized under: Range Functions / Math.