Main Content

mxCreateNumericArray (C)

N-D numeric array

C Syntax

#include "matrix.h"
mxArray *mxCreateNumericArray(mwSize ndim, const mwSize *dims,
    mxClassID classid, mxComplexity ComplexFlag);

Description

Use mxCreateNumericArray to create an N-dimensional mxArray. The data elements have the numeric data type specified by classid.

mxCreateNumericArray differs from mxCreateDoubleMatrix as follows:

  • All data elements in mxCreateDoubleMatrix are double-precision, floating-point numbers. The data elements in mxCreateNumericArray can be any numerical type, including different integer precisions.

  • mxCreateDoubleMatrix creates two-dimensional arrays only. mxCreateNumericArray can create arrays of two or more dimensions.

MATLAB® automatically removes any trailing singleton dimensions specified in the dims argument. For example, if ndim equals 5 and dims equals [4 1 7 1 1], then the resulting array has the dimensions 4-by-1-by-7.

This table shows the C classid values that are equivalent to MATLAB classes.

MATLAB Class Name

C classid Value

int8

mxINT8_CLASS

uint8

mxUINT8_CLASS

int16

mxINT16_CLASS

uint16

mxUINT16_CLASS

int32

mxINT32_CLASS

uint32

mxUINT32_CLASS

int64

mxINT64_CLASS

uint64

mxUINT64_CLASS

single

mxSINGLE_CLASS

double

mxDOUBLE_CLASS

Call mxDestroyArray when you finish using the mxArray. The mxDestroyArray function deallocates the mxArray and its associated real and imaginary elements.

Input Arguments

expand all

Number of dimensions, specified as mwSize. If ndim is less than 2, then mxCreateNumericArray sets the number of dimensions to 2.

Dimensions array, specified as const mwSize *.

Each element in the dimensions array contains the size of the array in that dimension. For example, to create a 5-by-7 array, set dims[0] to 5 and dims[1] to 7.

Usually, the dims array contains ndim elements.

Class identifier, specified as an mxClassID enumeration. classid determines how the numerical data is represented in memory. For example, mxCreateNumericMatrix stores mxINT16_CLASS values as 16-bit signed integers.

Complex array indicator, specified as an mxComplexity value.

For applications built with the mex -R2018a command, the function initializes each data element to 0.

For all other mex release-specific build options, the function sets each element in the pr array. If ComplexFlag is mxCOMPLEX, then the function sets the pi array to 0.

Output Arguments

expand all

Pointer to an mxArray of type classid, specified as mxArray *.

The function is unsuccessful when there is not enough free heap space to create the mxArray.

  • MEX file — Function terminates the MEX file and returns control to the MATLAB prompt.

  • Standalone (non-MEX file) application — Function returns NULL.

Examples

See these examples in matlabroot/extern/examples/refbook:

See these examples in matlabroot/extern/examples/mx:

Version History

Introduced before R2006a