C MEX File Applications

Write C/C++ programs using mxArray that work with MATLAB®


Functions in the C MEX APIs work with the MATLAB mxArray data type, which is defined in the C Matrix API. To write applications using modern C++ features, see C++ MEX Applications.

You can call your own C or C++ programs from the MATLAB command line as if they were built-in functions. These programs are called MEX files and the function name is the MEX file name.

To create a MEX file, write your programs using MATLAB APIs. The functions in these libraries facilitate the transfer of data between MEX files and the workspace. Choose either the C Matrix API or the MATLAB Data API; you cannot mix functions from these APIs.

Build your source file into an executable program using the mex function. You can also share the MEX file with other MATLAB users.

If you have a C/C++ program and want to call MATLAB functions from the program, then use one of the engine APIs.

If you want to read and write MATLAB data from C/C++ programs, then use the MATLAB C API to Read MAT-File Data.

Related Information