Write C++ Functions Callable from MATLAB (MEX Files) - MATLAB & Simulink (original) (raw)

Create high-performance functions, implemented in modern C++, that can be called from MATLABĀ®

Use the C++ MEX API to create MATLAB functions that provide the efficiency of C++ programs and that can access external functions and libraries from MATLAB. The C++ MEX API provides these features:

Note

Functions in the MATLAB C++ APIs use the matlab::data::Array class defined in the MATLAB Data API for C++. If your MEX functions must run in MATLAB R2017b or earlier, or if you prefer to work in the C language, then use the C Matrix API, which works with the mxArray data structure instead. For more information, see Write C Functions Callable from MATLAB (MEX Files).

Build Function

mex Build MEX functions and engine or MAT file applications

C++ Classes

matlab::mex::Function Base class for C++ MEX functions
matlab::mex::ArgumentList Container for inputs and outputs from C++ MEX functions

Out-of-Process Execution

mexhost Create host process for C++ MEX function
feval Evaluate C++ MEX function in MEX host process
matlab.mex.MexHost Out-of-process host for C++ MEX function execution

Topics

Create C++ MEX Functions

Setup and Build MEX Files

Design of C++ MEX Functions

MATLAB Data Types in MEX Functions

Call MATLAB Functions

Separate Threads and Processes

Access MATLAB Variables