NaN - Create array of all NaN values - MATLAB (original) (raw)

Create array of all NaN values

Syntax

Description

[X](#mw%5Fafb116f8-769e-4cee-bc31-1bb62afb480c) = NaN returns the scalar representation of "not a number". Operations return NaN when they have undefined numeric results, such as 0/0 or0*Inf.

[X](#mw%5Fafb116f8-769e-4cee-bc31-1bb62afb480c) = NaN([n](#d126e1160660)) returns ann-by-n matrix of NaN values.

example

[X](#mw%5Fafb116f8-769e-4cee-bc31-1bb62afb480c) = NaN([sz1,...,szN](#mw%5Fb597fd4e-0d30-4b48-8feb-76483f094a3c)) returns an sz1-by-...-by-szN array ofNaN values, where sz1,...,szN indicate the size of each dimension. For example, NaN(3,4) returns a 3-by-4 matrix.

example

[X](#mw%5Fafb116f8-769e-4cee-bc31-1bb62afb480c) = NaN([sz](#mw%5Ffdda7c2e-68e5-4498-8776-7f6a5f3a83ce)) returns an array of NaN values, where the size vector sz defines size(X). For example, NaN([3 4]) returns a 3-by-4 matrix.

example

[X](#mw%5Fafb116f8-769e-4cee-bc31-1bb62afb480c) = NaN(___,[typename](#mw%5F218f8ea7-8bb3-4402-adaf-89a7accc51ce)) returns an array of NaN values of data typetypename, which can be either "single" or"double".

example

[X](#mw%5Fafb116f8-769e-4cee-bc31-1bb62afb480c) = NaN(___,like=[p](#mw%5F6bb64174-2f2b-47dc-a3d3-7a49c3f3aa80)) returns an array of NaN values of the same data type, sparsity, and complexity (real or complex) as p. You can specifytypename or like but not both.

example

Examples

collapse all

Create a 3-by-3 matrix of NaN values.

X = 3×3

NaN NaN NaN NaN NaN NaN NaN NaN NaN

Create a 2-by-3-by-4 array of NaN values and display its size.

Create an array of NaN values that is the same size as an existing array.

A = [1 4; 2 5; 3 6]; sz = size(A); X = NaN(sz)

X = 3×2

NaN NaN NaN NaN NaN NaN

It is a common pattern to combine the previous two lines of code into a single line.

Create a 1-by-3 vector of NaN values whose elements are of type single.

X = 1×3 single row vector

NaN NaN NaN

You can also specify the output type based on the type of another variable. Create a variable p of type single. Then, create a vector of NaN values with the same size and type as p.

p = single([1 2 3]); X = NaN(size(p),like=p)

X = 1×3 single row vector

NaN NaN NaN

Input Arguments

collapse all

Size of square matrix, specified as an integer.

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

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

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.

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

Data type to create, specified as "double" or"single".

Prototype of array to create, specified as an array.

Data Types: double | single
Complex Number Support: Yes

Output Arguments

collapse all

Array of NaN values, returned as a scalar, vector, matrix, or multidimensional array.

Tips

Extended Capabilities

expand all

Usage notes and limitations:

Usage notes and limitations:

The NaN function supports GPU array input with these usage notes and limitations:

For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).

Usage notes and limitations:

For more information, see Run MATLAB Functions with Distributed Arrays (Parallel Computing Toolbox).

Version History

Introduced before R2006a