Create or Delete Array

Create array of specified type, allocate and free memory

Use the mxCreate* functions to create MATLAB® arrays. Use the mxCalloc, mxMalloc, and mxRealloc functions to allocate dynamic memory.

You allocate memory whenever you use an mxCreate* function or when you call the mxCalloc and associated functions. Use mxDestroyArray to free memory allocated by the mxCreate* functions. Use mxFree to free memory allocated by the mxCalloc and associated functions.

C Functions

expand all

mxCreateDoubleMatrix2-D, double-precision, floating-point array
mxCreateDoubleScalarScalar, double-precision array initialized to specified value
mxCreateNumericMatrix2-D numeric matrix
mxCreateNumericArrayN-D numeric array
mxCreateUninitNumericMatrixUninitialized 2-D numeric matrix
mxCreateUninitNumericArrayUninitialized N-D numeric array
mxMakeArrayComplexConvert real mxArray to complex, preserving real data
mxMakeArrayRealConvert complex mxArray to real, preserving real data
mxCreateString1-N array initialized to specified string
mxCreateCharMatrixFromStrings2-D mxChar array initialized to specified value
mxCreateCharArrayN-D mxChar array
mxCreateLogicalScalarScalar, logical array
mxCreateLogicalMatrix2-D logical array
mxCreateLogicalArrayN-D logical array
mxCreateSparseLogicalMatrix2-D, sparse, logical array
mxCreateSparse2-D sparse array
mxCreateSparseLogicalMatrix2-D, sparse, logical array
mxCreateStructMatrix2-D structure array
mxCreateStructArrayN-D structure array
mxCreateCellMatrix2-D cell array
mxCreateCellArrayN-D cell array
mxDestroyArrayFree dynamic memory allocated by MXCREATE* functions
mxDuplicateArrayMake deep copy of array
mxCallocAllocate dynamic memory for array, initialized to 0, using MATLAB memory manager
mxMallocAllocate uninitialized dynamic memory using MATLAB memory manager
mxReallocReallocate dynamic memory using MATLAB memory manager
mxFreeFree dynamic memory allocated by mxCalloc, mxMalloc, mxRealloc, mxArrayToString, or mxArrayToUTF8String functions

Topics

Pass Strings

This example shows how to pass strings to a MEX file.