| MATLAB® | ![]() |
Create numeric matrix and initialize data elements to 0
#include "matrix.h" mxArray *mxCreateNumericMatrix(mwSize m, mwSize n, mxClassID classid, mxComplexity ComplexFlag);
mwPointer mxCreateNumericMatrix(m, n, classid, ComplexFlag) mwSize m, n integer*4 classid, ComplexFlag
The desired number of rows.
The desired number of columns.
An 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. See the Description section for more information.
If the data you plan to put into the mxArray has no imaginary components, specify mxREAL in C (0 in Fortran). If the data has some imaginary components, specify mxCOMPLEX in C (1 in Fortran).
A pointer to the created mxArray, if successful. mxCreateNumericMatrix is unsuccessful if there is not enough free heap space to create the mxArray. If mxCreateNumericMatrix is unsuccessful in a MEX-file, the MEX-file prints an "Out of Memory" message, terminates, and control returns to the MATLAB prompt. If mxCreateNumericMatrix is unsuccessful in a stand alone (non-MEX-file) application, mxCreateNumericMatrix returns NULL in C (0 in Fortran).
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 |
To create a 4-by-3 matrix of REAL*4 elements having no imaginary components, use:
C Create 4x3 mxArray of REAL*4
mxCreateNumericMatrix(4, 3,
+ mxClassIDFromClassName('single'), 0)mxClassId, mxClassIdFromClassName, mxComplexity, mxCreateNumericArray
![]() | mxCreateNumericArray (C and Fortran) | mxCreateSparse (C and Fortran) | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |