主要内容

NaN

Create array of allNaN价值

Description

x = nan返回“不是数字”的标量表示。运营返回NaNwhen they have undefined numeric results, such as0/0要么0*Inf

example

x = nan(n)返回A.n-通过-nmatrix ofNaN价值。

example

x = nan(sz1,...,szn)返回A.sz1-通过-。..-by-szN阵列ofNaN价值, wheresz1,...,sznindicate the size of each dimension. For example,南(3,4)returns a 3-by-4 matrix.

example

x = nan(sz)返回一系列NaN价值, where the size vectorszdefinessize(X)。For example,nan([3 4])returns a 3-by-4 matrix.

example

x = nan(___,typename.)返回一系列NaN数据类型的值typename.,它可以是'single'要么'double'

example

x = nan(___,'喜欢',p)返回一系列NaN价值of the same data type, sparsity, and complexity (real or complex) asp。You can specifytypename.要么'like'但不是两者。

Examples

collapse all

创建一个3×3矩阵NaN价值。

x = nan(3)
X =3×3NaN NaN NaN NaN NaN NaN NaN NaN NaN

创建一个2×3×4阵列NaN值并显示其大小。

x = nan(2,3,4); size(X)
ans =1×32 3 4

Create an array ofNaN价值that is the same size as an existing array.

a = [1 4;2 5;3 6];sz =尺寸(a);X = NAN(SZ)
X =3×2NaN NaN NaN NaN NaN NaN

将前一行代码组合成单行是一种常见的模式。

x = nan(size(A));

Create a 1-by-3 vector ofNaN价值whose elements are of typesingle

x = nan(1,3,'single')
X =1x3 single row vectorNaN NaN NaN

You can also specify the output type based on the type of another variable. Create a variablepof typesingle。该n, create a vector ofNaN价值with the same size and type asp

p =单身([1 2 3]);x = nan(尺寸(p),'like',p)
X =1x3 single row vectorNaN NaN NaN

Input Arguments

collapse all

Size of square matrix, specified as an integer.

  • Ifn是0,然后Xis an empty matrix.

  • Ifnis negative, then it is treated as 0.

Data Types:double|single|int8|int16|INT32.|int64|uint8|uint16|uint32|uint64

Size of each dimension in a list, specified as separate integer arguments.

  • If the size of any dimension is 0, thenXis an empty array.

  • If the size of any dimension is negative, then it is treated as 0.

  • Beyond the second dimension,NaNignores trailing dimensions of length 1. For example,NaN(3,1,1)creates a 3-by-1 vector ofNaN价值。

Data Types:double|single|int8|int16|INT32.|int64|uint8|uint16|uint32|uint64

Size of each dimension in a vector, specified as a row vector of integers.

  • If the size of any dimension is 0, thenXis an empty array.

  • If the size of any dimension is negative, then it is treated as 0.

  • Beyond the second dimension,NaNignores trailing dimensions of length 1. For example,NaN([3 1 1])creates a 3-by-1 vector ofNaN价值。

Data Types:double|single|int8|int16|INT32.|int64|uint8|uint16|uint32|uint64

数据类型to create, specified as'double'要么'single'

要创建的数组原型,指定为数组。

Data Types:double|single
Complex Number Support:Yes

提示

  • x = nanreturns the scalar, typedouble, IEEE®representation of "not a number". The exact bit-wise hexadecimal representation of this value isfff8000000000000。MATLAB®保留备用的“不是数字”状态NaNrepresentations 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 canonicalNaN先前描述的位模式。

  • NaN价值are not equal to each other. As a result, comparison operations involvingNaNreturn false, except for the not equal operator〜=。For example,NaN == NaN返回逻辑0(false) butnan〜= nan返回逻辑1(真正).

  • NaN价值in a vector are treated as different unique elements. For example,unique([1 1 NaN NaN])returns the row vector[1 NaN NaN]

  • Use theisnan要么ismissing可以检测NaN数组中的值。该rmmissing.功能检测和删除NaN价值, and thefillmissing功能检测NaN价值and replaces them with non-NaN价值。

Extended Capabilities

在R2006A之前介绍