Main Content

C with MATLAB

Directly call C library functionality from MATLAB® using calllib or write C programs that call MATLAB functions using mxArray to access or create MATLAB variables in C

MATLAB provides multiple interfaces to C and C++ language programs. Whenever possible, choose the C++ interfaces over the C-only versions. For more information, see C++ with MATLAB.

  • If you need to maintain existing code that calls C shared library functionality using the calllib function, then see Call C from MATLAB. For using C libraries with MATLAB R2022a or later, see Call C++ from MATLAB.

  • To launch MATLAB from C programs, evaluate MATLAB functions with arguments, and exchange data between MATLAB and C programs, use the MATLAB engine API for C. For more information, see Call MATLAB from C.

  • To create MATLAB functions that provide the efficiency of C programs and that can access external functions and libraries from MATLAB, use the C MEX API. For more information, see Write C Functions Callable from MATLAB (MEX Files).

  • If you must write a custom program to interact with MATLAB data — for example, you want to read data from an external application, but you do not have access to the source code — then see Write C Programs to Read MAT-File Data

If you write C programs, you can use this code to work with MATLAB data using the C Matrix API. This interface has limited C++ language support.

Kategorien

Verwandte Informationen