Documentation

NaN

Not-a-Number

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

NaNreturns the IEEE®arithmetic representation for Not-a-Number (NaN). These values result from operations which haveundefined numerical results.

N = NaN(n)is ann-by-nmatrix ofNaNvalues.

N = NaN(sz1,...,szN)is asz1-by-...-by-szNarray ofNaNvalues wheresz1,...,szNindicates the size of each dimension. For example,NaN(3,4)返回一个3-by-4 array ofNaNvalues.

N = NaN(sz)is an array ofNaNvalues where the size vector,sz, definessize(N). For example,NaN([3,4])返回一个3-by-4 array ofNaNvalues.

    NoteThe size inputssz1,...,szN, as well as the elements of the size vectorsz, should be nonnegative integers. Negative integers are treated as 0.

N = NaN(classname)返回一个NaNvalue where the string,classname, specifies the data type.classnamecan be either'single'or'double'.

N = NaN(n,classname)返回一个nn-by-narray ofNaNvalues of data typeclassname.

N = NaN(sz1,...szN,classname)返回一个sz1-by-...-by-szNarray ofNaNvalues of data typeclassname.

N = NaN(sz,classname)返回一个n array ofNaNvalues where the size vector,sz, definessize(N)andclassnamedefinesclass(N).

N = NaN('like',p)返回一个NaNvalue of the same data type, sparsity, and complexity (real or complex) as the numeric variable,p.

N = NaN(n,'like',p)返回一个nn-by-narray ofNaNvalues likep.

N = NaN(sz1,...szN,'like',p)返回一个sz1-by-...-by-szNarray ofNaNvalues likep.

N = NaN(sz,'like',p)返回一个n array ofNaNvalues likepwhere the size vector,sz, definessize(N).

Examples

这些操作公关oduceNaN:

  • Any arithmetic operation on aNaN, such assqrt(NaN)

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

  • Multiplication, such as0*Inf

  • Division, such as0/0andInf/Inf

  • Remainder, such asrem(x,y)whereyis zero orxis infinity

Tips

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

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

and theNaNs in a vector are treated as different unique elements.

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

Use theisnanfunction to detectNaNs in an array.

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

Extended Capabilities

Introduced before R2006a

Was this topic helpful?