Main Content

C++ with MATLAB

Directly call C/C++ library functionality from MATLAB® or write modern C++ programs that call MATLAB functions

There are several ways to connect C/C++ and MATLAB:

  • Shared libraries—If you have a C or C++ shared library that exports functionality, you can build and package a MATLAB interface to that library and share it with a MATLAB user. For details, see Call C++ from MATLAB.

  • Access MATLAB from C++—To write C++ programs that launch MATLAB, evaluate MATLAB functions with arguments, and exchange data between MATLAB and C++ programs, use the MATLAB Engine API for C++. For details, see Call MATLAB from C++. To work with MATLAB data, see MATLAB Data API for C++.

  • Run C++ code from MATLAB (MEX files)—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 details, see Write C++ Functions Callable from MATLAB (MEX Files).

Some existing code uses C interfaces that call the loadlibrary function or include the C Matrix API, but those interfaces have limited C++ language support. If you need to maintain such code, see Call C from MATLAB.

Categories