NaN

Not-a-Number: the value produced by undefined operations such as 0/0, and a way to create arrays filled with it.

Category: Language Fundamentals > Data Types

Syntax

NaN

The scalar NaN.

X = NaN(n)

An n-by-n matrix of NaN.

X = NaN(sz1, sz2, ...)

An array with the given dimensions.

X = NaN(___, classname)

Creates the array as 'double' or 'single'.

Description

NaN is a floating-point value that means a result is not a number. Any arithmetic with NaN gives NaN, and NaN is not equal to anything, itself included, so NaN == NaN is false. Test for it with isnan.

Functions such as max, min, sum and mean handle NaN in different ways: max and min skip it, while sum and mean propagate it unless an 'omitnan' flag is given. NaN exists only for floating-point types; integer types have no NaN.

Input arguments

n, sz1, sz2, ...
Non-negative integers giving the size.
classname
'double' (default) or 'single'.

Output arguments

X
Array of NaN values.

Example

x = 0/0
NaN(1, 3)
NaN == NaN
isnan([1 NaN 3])
class(NaN(2, 'single'))
Output
x = NaN
ans = 1×3

   NaN   NaN   NaN
ans = logical
   0
ans = 1×3 logical array

   0   1   0
ans = 'single'

See also

isnan Inf nan rmmissing fillmissing