isnan - Determine which array elements are NaN - MATLAB (original) (raw)
Determine which array elements are NaN
Syntax
Description
`TF` = isnan([A](#mw%5Fdb2dcfa9-acb4-48e9-a017-ee0c39f1f741))
returns a logical array containing 1
(true
) where the elements of A
are NaN
, and 0
(false
) where they are not. If A
contains complex numbers, isnan(A)
contains 1
for elements with either real or imaginary part is NaN
, and 0
for elements where both real and imaginary parts are not NaN
.
Examples
Create a row vector and determine which elements are NaN
.
TF = 1×5 logical array
0 0 1 0 0
Create an array of complex numbers. Determine whether the complex numbers contain NaN
.
A = [2 + 1i, 1/0 + 3i, 1/2 - 1i*NaN]
A = 1×3 complex
2.0000 + 1.0000i Inf + 3.0000i 0.5000 + NaNi
TF = 1×3 logical array
0 0 1
Create an array and find the elements with NaN
values.
A = [1,3,5,7,NaN,10,NaN,4,6,8]
A = 1×10
1 3 5 7 NaN 10 NaN 4 6 8
TF = 1×10 logical array
0 0 0 0 1 0 1 0 0 0
Index into A
with TF
to access the elements of A
that are NaN
. Replace the NaN
values with 0.
A = 1×10
1 3 5 7 0 10 0 4 6 8
Input Arguments
Input array, specified as a scalar, vector, matrix, or multidimensional array.
Tips
- If
x
is a real scalar, exactly one ofisfinite(x)
,isinf(x)
, andisnan(x)
returns logical1
(true
). - For a complex scalar
z
,isinf(z)
andisnan(z)
can both return logical 1. For example,isinf(complex(Inf,NaN))
andisnan(complex(Inf,NaN))
both return logical 1.
Extended Capabilities
Theisnan
function fully supports tall arrays. For more information, see Tall Arrays.
The isnan
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 before R2006a