Documentation Center

  • Trial Software
  • Product Updates

mxCreateNumericMatrix (C and Fortran)

2-D numeric matrix

C Syntax

#include "matrix.h"
mxArray *mxCreateNumericMatrix(mwSize m, mwSize n, 
  mxClassID classid, mxComplexity ComplexFlag);

Fortran Syntax

mwPointer mxCreateNumericMatrix(m, n, classid, 
  ComplexFlag)
mwSize m, n
integer*4 classid, ComplexFlag

Arguments

m

Number of rows

n

Number of columns

classid

Identifier for the class of the array, which determines the way the numerical data is represented in memory. For example, specifying mxINT16_CLASS in C causes each piece of numerical data in the mxArray to be represented as a 16-bit signed integer. In Fortran, use the function mxClassIDFromClassName to derive the classid value from a MATLAB® class name.

ComplexFlag

If the mxArray you are creating is to contain imaginary data, set ComplexFlag to mxCOMPLEX in C (1 in Fortran). Otherwise, set ComplexFlag to mxREAL in C (0 in Fortran).

Returns

Pointer to the created mxArray, if successful. If unsuccessful in a standalone (non-MEX-file) application, returns NULL in C (0 in Fortran). If unsuccessful in a MEX-file, the MEX-file terminates and returns control to the MATLAB prompt. The function is unsuccessful when there is not enough free heap space to create the mxArray.

Description

Call mxCreateNumericMatrix to create a 2-D mxArray in which all data elements have the numeric data type specified by classid. After creating the mxArray, mxCreateNumericMatrix initializes all its real data elements to 0. If ComplexFlag equals mxCOMPLEX in C (1 in Fortran), mxCreateNumericMatrix also initializes all its imaginary data elements to 0. mxCreateNumericMatrix allocates dynamic memory to store the created mxArray. When you finish using the mxArray, call mxDestroyArray to destroy it.

The following table shows the C classid values and the Fortran data types that are equivalent to MATLAB classes.

MATLAB Class Name

C classid Value

Fortran Type

int8

mxINT8_CLASS

BYTE

uint8

mxUINT8_CLASS

 

int16

mxINT16_CLASS

INTEGER*2

uint16

mxUINT16_CLASS

 

int32

mxINT32_CLASS

INTEGER*4

uint32

mxUINT32_CLASS

 

int64

mxINT64_CLASS

INTEGER*8

uint64

mxUINT64_CLASS

 

single

mxSINGLE_CLASS

REAL*4

double

mxDOUBLE_CLASS

REAL*8

single, with imaginary components

mxSINGLE_CLASS

COMPLEX*8

double, with imaginary components

mxDOUBLE_CLASS

COMPLEX*16

Examples

See the following examples in matlabroot/extern/examples/refbook.

The following Fortran statements create a 4-by-3 matrix of REAL*4 elements having no imaginary components:

C      Create 4x3 mxArray of REAL*4
       mxCreateNumericMatrix(4, 3,
     +                mxClassIDFromClassName('single'), 0)
Was this topic helpful?