Main Content

anynan

Determine if any array element is NaN

Since R2022a

Description

TF = anynan(A) returns logical 1 (true) if at least one element of A is NaN. It returns 0 (false) if no element is NaN.

If A contains complex numbers, anynan(A) returns 1 if at least one element has a real or imaginary part that is NaN.

example

Examples

collapse all

Create a row vector A. Determine if at least one element of A is NaN.

A = 0./[-2 -1 0 1 2]
A = 1×5

     0     0   NaN     0     0

TF = anynan(A)
TF = logical
   1

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 = [-2 -1 1 2]/0
B = 1×4

  -Inf  -Inf   Inf   Inf

TF = anynan(B)
TF = logical
   0

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

TF = anynan(A)
TF = logical
   1

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

TF = anynan(A)
TF = logical
   0

Input Arguments

collapse all

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

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

Version History

Introduced in R2022a