anynan - Determine if any array element is NaN - MATLAB (original) (raw)
Main Content
Determine if any array element is NaN
Since R2022a
Syntax
Description
`TF` = anynan([A](#mw%5Fb3e8dab7-6c6c-4c8c-9135-e1772f6e1977))
returns logical 1
(true
) if at least one element ofA
is NaN
. It returns 0
(false
) if no element is NaN
.
If A
contains complex numbers, anynan(A)
returns1
if at least one element has a real or imaginary part that isNaN
.
Examples
Create a row vector A
. Determine if at least one element of A
is NaN
.
anynan
returns logical 1
(true
) because at least one element of A
is NaN
.
Create another row vector B
. Determine if at least one element of B
is NaN
.
B = 1×4
-Inf -Inf Inf Inf
anynan
returns logical 0
(false
) because no element of B
is NaN
.
Create a matrix and determine if at least one of its elements is NaN
.
A = [0 0 3;0 0 3;0 0 NaN]
A = 3×3
0 0 3
0 0 3
0 0 NaN
Create a 3-D array and determine if at least one of its elements is NaN
.
A(:,:,1) = [2 1; 3 5]; A(:,:,2) = [0 0; 0 Inf]; A(:,:,3) = [-2 9; 4 1]
A = A(:,:,1) =
2 1
3 5
A(:,:,2) =
0 0
0 Inf
A(:,:,3) =
-2 9
4 1
Input Arguments
Input array, specified as a scalar, vector, matrix, or multidimensional array.
Example: [pi NaN Inf -Inf]
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| logical
| char
| duration
| calendarDuration
Complex Number Support: Yes
Extended Capabilities
Theanynan
function fully supports tall arrays. For more information, see Tall Arrays.
The anynan
function fully supports GPU arrays. To run the function on a GPU, specify the input data as a gpuArray (Parallel Computing Toolbox). For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).
Version History
Introduced in R2022a