isnan
Marks elements that are NaN (not a number).
Category: Language Fundamentals > Data Types
Syntax
tf = isnan(A)
Returns a logical array that is true where A is NaN.
Description
NaN is not equal to anything, itself included, so x == NaN is always false. The only reliable way to detect it is isnan.
Common uses are removing bad data, x(~isnan(x)), or counting it with sum(isnan(x)). Integer types have no NaN and give all false.
Input arguments
A- Numeric or logical array. A complex number is NaN if either part is NaN.
Output arguments
tf- Logical array the same size as
A.
Example
Detecting and counting NaN
x = [4 NaN 7 NaN 1];
isnan(x)
x(~isnan(x))
sum(isnan(x))
NaN == NaN
Output
ans = 1×5 logical array
0 1 0 1 0
ans = 1×3
4 7 1
ans = 2
ans = logical
0