NaN

Array of Not-a-Numbers

Syntax

A = NaN(sz,arraytype)
A = NaN(sz,datatype,arraytype)

A = NaN(sz,'like',P)
A = NaN(sz,datatype,'like',P)

C = NaN(sz,codist)
C = NaN(sz,datatype,codist)
C = NaN(sz,___,codist,'noCommunication')
C = NaN(sz,___,codist,'like',P)

Description

A = NaN(sz,arraytype) creates a matrix with underlying class of double, with NaN values in all elements.

A = NaN(sz,datatype,arraytype) creates a matrix with underlying class of datatype, with NaN values in all elements.

The size and type of array are specified by the argument options according to the following table.

ArgumentValuesDescriptions
sznSpecifies size as an n-by-n matrix.
m,n or [m n]Specifies size as an m-by-n matrix.
m,n,...,k or [m n ... k]Specifies size as an m-by-n-by-...-by-k array.
arraytype'distributed'Specifies distributed array.
'codistributed'Specifies codistributed array, using the default distribution scheme.
'gpuArray'Specifies gpuArray.
datatype'double' (default), 'single'Specifies underlying class of the array, i.e., the data type of its elements.

A = NaN(sz,'like',P) creates an array of NaN values with the same type and underlying class (data type) as array P.

A = NaN(sz,datatype,'like',P) creates an array of NaN values with the specified underlying class (datatype), and the same type as array P.

C = NaN(sz,codist) or C = NaN(sz,datatype,codist) creates a codistributed array of NaN values with the specified size and underlying class (the default datatype is 'double'). The codistributor object codist specifies the distribution scheme for creating the codistributed array. For information on constructing codistributor objects, see the reference pages for codistributor1d and codistributor2dbc. To use the default distribution scheme, you can specify a codistributor constructor without arguments. For example:

spmd
    C = NaN(8,codistributor1d());
end

C = NaN(sz,___,codist,'noCommunication') specifies that no interworker communication is to be performed when constructing a codistributed array, skipping some error checking steps.

C = NaN(sz,___,codist,'like',P) creates a codistributed array of NaN values with the specified size, underlying class, and distribution scheme. If either the class or codistributor argument is omitted, the characteristic is acquired from the codistributed array P.

Examples

Create Distributed NaN Matrix

Create a 1000-by-1000 distributed matrix of NaNs with underlying class double:

D = NaN(1000,'distributed');

Create Codistributed NaN Matrix

Create a 1000-by-1000 codistributed double matrix of NaNs, distributed by its second dimension (columns).

spmd(4)
    C = NaN(1000,'codistributed');
end

With four workers, each worker contains a 1000-by-250 local piece of C.

Create a 1000-by-1000 codistributed single matrix of NaNs, distributed by its columns.

spmd(4)
    codist = codistributor('1d',2,100*[1:numlabs]);
    C = NaN(1000,1000,'single',codist);
end

Each worker contains a 100-by-labindex local piece of C.

Create gpuArray NaN Matrix

Create a 1000-by-1000 gpuArray of NaNs with underlying class double:

G = NaN(1000,'double','gpuArray');

See Also

| | | | | |

Introduced in R2006b

Was this topic helpful?