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
N = NaN(n)
is ann
-by-n
matrix ofNaN
values.
N = NaN(sz1,...,szN)
is asz1
-by-...-by-szN
array ofNaN
values wheresz1,...,szN
indicates the size of each dimension. For example,NaN(3,4)
返回一个3-by-4 array ofNaN
values.
N = NaN(sz)
is an array ofNaN
values where the size vector,sz
, definessize(N)
. For example,NaN([3,4])
返回一个3-by-4 array ofNaN
values.
NoteThe size inputs |
N = NaN(classname)
返回一个NaN
value where the string,classname
, specifies the data type.classname
can be either'single'
or'double'
.
N = NaN(n,classname)
返回一个nn
-by-n
array ofNaN
values of data typeclassname
.
N = NaN(sz1,...szN,classname)
返回一个sz1
-by-...-by-szN
array ofNaN
values of data typeclassname
.
N = NaN(sz,classname)
返回一个n array ofNaN
values where the size vector,sz
, definessize(N)
andclassname
definesclass(N)
.
N = NaN('like',p)
返回一个NaN
value of the same data type, sparsity, and complexity (real or complex) as the numeric variable,p
.
N = NaN(n,'like',p)
返回一个nn
-by-n
array ofNaN
values likep
.
N = NaN(sz1,...szN,'like',p)
返回一个sz1
-by-...-by-szN
array ofNaN
values likep
.
N = NaN(sz,'like',p)
返回一个n array ofNaN
values likep
where the size vector,sz
, definessize(N)
.
Examples
这些操作公关oduceNaN
:
Any arithmetic operation on a
NaN
, such assqrt(NaN)
Addition or subtraction, such as magnitude subtraction of infinities as
(+Inf)+(-Inf)
Multiplication, such as
0*Inf
Division, such as
0/0
andInf/Inf
Remainder, such as
rem(x,y)
wherey
is zero orx
is infinity
Tips
Because twoNaN
s are not equal to each other, logical operations involvingNaN
s always return false, except ~= (not equal). Consequently,
NaN ~= NaN ans = 1 NaN == NaN ans = 0
and theNaN
s in a vector are treated as different unique elements.
unique([1 1 NaN NaN]) ans = 1 NaN NaN
Use theisnan
function to detectNaN
s in an array.
isnan([1 1 NaN NaN]) ans = 0 0 1 1