Call MATLAB from C++
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. Supported operations include:
Start MATLAB.
Connect to a MATLAB shared session on the local machine.
Call MATLAB functions with input arguments passed from C++ and output variables returned from MATLAB.
Evaluate MATLAB statements in the MATLAB base workspace.
Pass variables from C++ to MATLAB and from MATLAB to C++.
To get started, see Set Up C++ Development Environment.
The MATLAB Engine API for C++ uses the MATLAB Data API for C++, which provides a way for applications running outside of MATLAB to work with MATLAB data through a language-neutral interface. The engine API also provides a strongly typed interface that enforces a strict data type mapping between MATLAB and C++. You can use this strongly typed interface to call MATLAB functions and classes by their MATLAB names in C++ as if they were native C++ functions and classes. For an example, see Integrate Strongly Typed MATLAB Data in C++ Application.
Classes
Functions
Topics
Requirements
- Requirements to Build C++ Engine Applications
Install and configure a compiler and run-time environment so you can build C++ applications to call MATLAB. - Set Up C++ Development Environment
Set up a development environment to write C++ applications that call MATLAB functions.
Integrate MATLAB Code in C++
- Structure of C++ Engine Applications
Get started with the MATLAB Engine API for C++. - Integrate MATLAB Function in C++ Application
Create a C++ engine application using the MATLAB Engine and Data APIs. - Integrate Strongly Typed MATLAB Data in C++ Application
Use strongly typed data with the MATLAB Engine API for C++.
Start and Connect to MATLAB
- Start MATLAB Sessions from C++
Start and connect to a MATLAB session synchronously or asynchronously from C++. - Connect C++ to Running MATLAB Session
Connect a C++ application to a MATLAB session that was started as or converted to a shared session.
Call MATLAB Functions
- Call MATLAB Functions from C++
Call MATLAB functions from C++, passing variables to MATLAB and returning variables to C++. - Evaluate MATLAB Statements from C++
Evaluate MATLAB statements in your C++ program, and write variables to 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 into 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 your C++ program. - Convert C++ Engine Application to MATLAB Compiler SDK Application
Convert an engine application to a deployed application using MATLAB Compiler SDK™.
Use MATLAB Data Types in C++
- Data Type Mappings Between C++ and Strongly Typed MATLAB Code
Refer to data type mappings between C++ and MATLAB when using strongly typed MATLAB code. - Create Structure Arrays from C++
Create structure arrays in C++ and pass them to MATLAB, or retrieve structure arrays from MATLAB. - Create Cell Arrays from C++
Create heterogeneous arrays in C++ to use as MATLAB cell arrays. - Pass Enumerations to MATLAB from C++
Pass members of a MATLAB enumeration class to MATLAB from C++. - Pass Sparse Arrays to MATLAB from C++
Pass arrays from C++ to MATLAB as MATLAB sparse arrays. - Use MATLAB Handle Classes in C++
Integrate MATLAB handle classes with C++ applications. - Limitations of Strongly Typed Interface for C++
Strongly typed interface for C++ features not supported in MATLAB.