Note: This page has been translated by MathWorks. Click here to see

To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Create array of all `NaN`

values

`X = NaN`

`X = NaN(n)`

`X = NaN(sz1,...,szN)`

`X = NaN(sz)`

`X = NaN(___,typename)`

`X = NaN(___,'like',p)`

`X = NaN`

returns the scalar representation of
Not-a-Number. `NaN`

results from operations that return undefined numeric
output, such as `0/0`

or `0*Inf`

.

`X = NaN(`

returns an
`sz1,...,szN`

)`sz1`

-by-...-by-`szN`

array of `NaN`

values, where `sz1,...,szN`

indicate the size of each dimension. For
example, `NaN(3,4)`

returns a 3-by-4 matrix.

`X = NaN(___,`

returns an
array of `typename`

)`NaN`

values of data type `typename`

, which can
be either `'single'`

or `'double'`

.

`X = NaN`

returns the scalar, type`double`

, IEEE^{®}representation of Not-A-Number. The exact bit-wise hexadecimal representation of this value is`fff8000000000000`

. MATLAB^{®}preserves the Not-A-Number status of alternate`NaN`

representations and treats all representations equivalently. In some special cases, due to hardware limitations for example, MATLAB does not preserve the exact bit pattern of the alternate representations during computation, and instead uses the canonical`NaN`

bit pattern previously described.`NaN`

values are not equal to each other, thus logical operations involving`NaN`

return false except for the not equal operator`~=`

. For example,`NaN == NaN`

returns logical 0 (`false`

) but`NaN ~= NaN`

returns logical 1 (`true`

).`NaN`

values in a vector are treated as different unique elements. For example,`unique([1 1 NaN NaN])`

returns the row vector`[1 NaN NaN]`

.Use the

`isnan`

or`ismissing`

functions to detect`NaN`

values in an array. The`rmmissing`

function detects and removes`NaN`

values, and the`fillmissing`

function detects`NaN`

values and replaces them with non-`NaN`

values.