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

Main Content

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 function or engine application

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

MathWorks - Domain Selector

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list

How to Get Best Site Performance

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.

Americas

Europe

Asia Pacific

Contact your local office