# Documentation

### This is machine translation

Translated by
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

# NaN

## Syntax

``NaN``
``N = NaN(n)``
``N = NaN(sz1,...,szN)``
``N = NaN(sz)``
``N = NaN(classname)``
``N = NaN(n,classname)``
``N = NaN(sz1,...szN,classname)``
``N = NaN(sz,classname)``
``N = NaN('like',p)``
``N = NaN(n,'like',p)``
``N = NaN(sz1,...szN,'like',p)``
``N = NaN(sz,'like',p)``

## Description

````NaN` returns the IEEE® arithmetic representation for Not-a-Number (`NaN`). These values result from operations which have undefined numerical results.```
````N = NaN(n)` is an `n`-by-`n` matrix of `NaN` values.```
````N = NaN(sz1,...,szN)` is a `sz1`-by-...-by-`szN` array of `NaN` values where `sz1,...,szN` indicates the size of each dimension. For example, `NaN(3,4)` returns a 3-by-4 array of `NaN` values.```
````N = NaN(sz)` is an array of `NaN` values where the size vector, `sz`, defines `size(N)`. For example, `NaN([3,4])` returns a 3-by-4 array of `NaN` values. NoteThe size inputs `sz1,...,szN`, as well as the elements of the size vector `sz`, should be nonnegative integers. Negative integers are treated as 0. ```
````N = NaN(classname)` returns a `NaN` value where the string, `classname`, specifies the data type. `classname` can be either `'single'` or `'double'`.```
````N = NaN(n,classname)` returns an `n`-by-`n` array of `NaN` values of data type `classname`.```
````N = NaN(sz1,...szN,classname)` returns a `sz1`-by-...-by-`szN` array of `NaN` values of data type `classname`.```
````N = NaN(sz,classname)` returns an array of `NaN` values where the size vector, `sz`, defines `size(N)` and `classname` defines `class(N)`.```
````N = NaN('like',p)` returns a `NaN` value of the same data type, sparsity, and complexity (real or complex) as the numeric variable, `p`.```
````N = NaN(n,'like',p)` returns an `n`-by-`n` array of `NaN` values like `p`.```
````N = NaN(sz1,...szN,'like',p)` returns a `sz1`-by-...-by-`szN` array of `NaN` values like `p`.```
````N = NaN(sz,'like',p)` returns an array of `NaN` values like `p` where the size vector, `sz`, defines `size(N)`.```

## Examples

These operations produce `NaN`:

• Any arithmetic operation on a `NaN`, such as `sqrt(NaN)`

• Addition or subtraction, such as magnitude subtraction of infinities as `(+Inf)+(-Inf)`

• Multiplication, such as `0*Inf`

• Division, such as `0/0` and `Inf/Inf`

• Remainder, such as `rem(x,y)` where `y` is zero or `x` is infinity

## Tips

Because two `NaN`s are not equal to each other, logical operations involving `NaN`s always return false, except ~= (not equal). Consequently,

```NaN ~= NaN ans = 1 NaN == NaN ans = 0```

and the `NaN`s in a vector are treated as different unique elements.

```unique([1 1 NaN NaN]) ans = 1 NaN NaN```

Use the `isnan` function to detect `NaN`s in an array.

```isnan([1 1 NaN NaN]) ans = 0 0 1 1```

## See Also

### Topics

#### Introduced before R2006a

Was this topic helpful?

#### The Manager's Guide to Solving the Big Data Conundrum

Download white paper