any

Returns a logical that indicates whether any of the corresponding elements of the input are nonzero.

Syntax

R = any(x)

R = any(x,dim)

Inputs

x
scalar | complex | vector | matrix
Type: double | integer | char | string | logical | struct | cell
Dimension: scalar | string | vector | matrix
dim
The dimension on which to operate
Default: first non-singleton dimension.
Type: integer
scalar

Outputs

R
scalar | vector | matrix

Examples

Vector input:

R = any([1,1,1,0])
R = 1

Matrix input:

R = any([1,0,1;0,0,0;1,0,1])
R = [Matrix] 1 x 3
1  0  1

Matrix input with dim:

R = any([1,0,1;0,0,0;1,0,1], 2)
R = [Matrix] 3 x 1
1
0
1

Comments

The output will be a matrix with the same dimensions as the input, except that each vector in the dimension of interest is replaced by a single logical value. For example, a 2D matrix input with no dimension specified will operate on each column and return a row vector.