Documentation

This is machine translation

Translated by Microsoft
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.

    Note   The 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

More About

collapse all

Tips

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

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

and the NaNs in a vector are treated as different unique elements.

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

Use the isnan function to detect NaNs in an array.

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

See Also

| | |

Introduced before R2006a

Was this topic helpful?