Help CenterHelp Center
NaN
Determine if any array element is NaN
TF = anynan(A)
example
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.
TF
A
1
true
0
false
If A contains complex numbers, anynan(A) returns 1 if at least one element has a real or imaginary part that is NaN.
anynan(A)
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 = logical 1
anynan returns logical 1 (true) because at least one element of A is NaN.
anynan
Create another row vector B. Determine if at least one element of B is NaN.
B
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
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 array, specified as a scalar, vector, matrix, or multidimensional array.
Example: [pi NaN Inf -Inf]
[pi NaN Inf -Inf]
Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical | char | duration | calendarDuration Complex Number Support: Yes
single
double
int8
int16
int32
int64
uint8
uint16
uint32
uint64
logical
char
duration
calendarDuration
any | NaN | isnan | ismissing | anymissing
any
isnan
ismissing
anymissing
You have a modified version of this example. Do you want to open this example with your edits?
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Contact your local office