Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

C MEX File Applications

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

Note

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 C++11 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

Was this topic helpful?