Main Content

MATLAB Engine API for C++

Run MATLAB® code from C++ programs, with object oriented programming support and asynchronous execution

The MATLAB Engine API for C++ provides an interface between the C++ programming language and MATLAB. This API enables C++ programs to launch MATLAB, evaluate MATLAB functions with arguments, and exchange data between MATLAB and C++ programs.

The MATLAB Engine API for C++ supports the MATLAB Data API, which provides a way for applications running outside of MATLAB to work with MATLAB data through a MATLAB-neutral interface. For more information on the MATLAB Data API, see MATLAB Data API.

Share MATLAB Session

matlab.engine.shareEngineConvert running MATLAB session to shared session

Start, Find, Connect, and Terminate MATLAB

matlab::engine::connectMATLABConnect to shared MATLAB session synchronously
matlab::engine::connectMATLABAsyncConnect to shared MATLAB session asynchronously
matlab::engine::findMATLABFind shared MATLAB sessions synchronously
matlab::engine::findMATLABAsyncFind shared MATLAB sessions asynchronously
matlab::engine::startMATLABStart MATLAB synchronously
matlab::engine::startMATLABAsyncStart MATLAB asynchronously
matlab::engine::terminateEngineClientFree engine resources during runtime

Type Conversions

matlab::engine::convertUTF8StringToUTF16StringConvert UTF-8 string to UTF-16 string
matlab::engine::convertUTF16StringToUTF8StringConvert UTF-16 string to UTF-8 string

Type Definitions

matlab::engine::StreamBuffer Define stream buffer
matlab::engine::String Define UTF16 string


matlab::engine::MATLABEngineEvaluate MATLAB functions from C++ program
matlab::engine::FutureResultRetrieve result from asynchronous operation
matlab::engine::SharedFutureResult Retrieve result from asynchronous operation as shared future
matlab::engine::WorkspaceTypeType of MATLAB workspace


Setup and Build Engine Applications

Introduction to Engine API for C++

Introduction to the basic design of a C++ engine program.

Build C++ Engine Programs

Build engine applications on different platforms.

Test Your Build Environment

Use this sample code to confirm your development environment for the MATLAB Engine API for C++.

C++ Engine API

The MATLAB Engine C++ API comprises functions, classes, and typedefs in matlab::engine namespace.

Start and Connect to MATLAB

Start MATLAB Sessions from C++

Start and connect to a MATLAB session synchronously and asynchronously from C++.

Connect C++ to Running MATLAB Session

Connect the C++ engine to a MATLAB session that has been started as or converted to a shared session.

Call Functions and Exchange Data

Call MATLAB Functions from C++

Call MATLAB functions from C++, passing variable to MATLAB and returning variables to C++.

Evaluate MATLAB Statements from C++

Evaluate MATLAB expression from C++ and write variables into the MATLAB base workspace.

Pass Variables from C++ to MATLAB

Pass variables from C++ to MATLAB as function arguments or by placing those variables directly in the MATLAB base workspace.

Pass Variables from MATLAB to C++

Get variables from the MATLAB base or global workspace.

Redirect MATLAB Command Window Output to C++

Redirect MATLAB command window output, including error messages, to you C++ program.

Run Simulink Simulation from C++

Run Simulink® model simulations from C++ and visualize the results with MATLAB graphics.

Convert C++ Engine Application to MATLAB Compiler SDK Application

How to convert an engine application to a deployed application using MATLAB Compiler SDK™.

Create MATLAB Data Types

Create Structure Arrays from C++

Create a structure array in C++ and pass it to MATLAB or get a structure array defined in MATLAB.

Create Cell Arrays from C++

Create heterogeneous arrays in C++ to use as MATLAB cell arrays.

Pass Enumerations to MATLAB From C++

Pass enumeration members of MATLAB enumeration classes to MATLAB from C++.

Pass Sparse Arrays to MATLAB From C++

Pass arrays to MATLAB as MATLAB sparse arrays.

Related Information