mxArray (C and Fortran) - Type for a MATLAB array

Description

The fundamental type underlying MATLAB data. For information on how the MATLAB array works with MATLAB-supported variables, see MATLAB Data in the External Interfaces documentation.

mxArray is a C language opaque type.

All C and Fortran MEX-files start with a gateway routine, called mexFunction, which requires mxArray for both input and output parameters. A C MEX-file gateway routine is described in C Source MEX-Files. The Fortran version is described in Fortran Source MEX-Files.

Once you have MATLAB data in your MEX-file, you can use the array access library routines (listed in MX Array Manipulation) to manipulate the data, and the MEX library routines (listed in MEX-Files) to perform operations in the MATLAB environment. You use mxArray to pass data to and from these functions.

Use any of the mxCreate* functions when you need to create data, and the corresponding mxDestroyArray function to free memory.

The header file containing this type is:

#include "matrix.h"

Example

See mxcreatecharmatrixfromstr.c in your matlabroot/extern/examples/mx directory.

The input argument prhs contains two or more strings, defined as mxArray. Use the mxIsChar function to validate the input. Create a C variable str of type char using the mxArrayToString function. Now you can manipulate your data in C.

To set the return values in plhs, use the mxCreateCharMatrixFromStrings function.

Before you exit your routine, be sure to free memory using the mxFree function on str.

See Also

mexFunction, mxClassID, mxCreateDoubleMatrix, mxCreateNumericArray, mxCreateString, mxDestroyArray, mxGetData, mxSetData

  


 © 1984-2008- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS