Main Content

matlab::engine::startMATLAB

Start MATLAB synchronously

Description

std::unique_ptr<MATLABEngine> startMATLAB(const std::vector<String>& options = std::vector<String>())

std::unique_ptr<MATLABEngine> startMATLAB(const matlab::engine::MATLABApplicationMode mode, const std::vector<String>& options = std::vector<String>()) (since R2026a)

Start MATLAB® synchronously with optional MATLAB startup options. If you do not specify an application mode, MATLAB starts in a separate process. Otherwise, MATLAB starts in the specified application mode. You cannot have an in-process and out-of-process engine in the same application.

Include

Namespace:

matlab::engine
IncludeMatlabEngine.hpp

Parameters

const std::vector<String>& options

Options used to start MATLAB. You can specify multiple startup options. The engine supports all MATLAB startup options, except for the options listed in Unsupported Startup Options. For a list of options, see the platform-specific command matlab (Windows), matlab (macOS), or matlab (Linux).

const matlab::engine::MATLABApplicationMode mode (since R2026a)

Mode in which to start application:

  • MATLABApplicationMode::IN_PROCESS

  • MATLABApplicationMode::OUT_OF_PROCESS

Only one in-process MATLAB startup is allowed per application run. If you call startMATLAB again when the in-process MATLAB session is active, the function returns a pointer to the existing MATLAB.

If you terminate an in-process MATLAB, you cannot restart another MATLAB.

An application can have either an in-process or an out-of-process engine.

For examples, see Start MATLAB Sessions from C++.

Return Value

std::unique_ptr<MATLABEngine>

Pointer to the MATLABEngine object

Exceptions

matlab::engine::EngineException

MATLAB failed to start.

Unsupported Startup Options

The engine does not support these MATLAB startup options:

  • -h

  • -help

  • -?

  • -n

  • -e

  • -logfile

For information on MATLAB startup options, see Commonly Used Startup Options.

Examples

expand all

Start MATLAB synchronously and return a unique pointer to the MATLABEngine object.

std::unique_ptr<MATLABEngine> matlabPtr = startMATLAB();
auto matlabApplication = matlab::engine::startMATLAB({u"-desktop"});

Start MATLAB with the -nojvm option and return a unique pointer to the MATLABEngine object.

std::vector<String> optionVec;
optionVec.push_back(u"-nojvm");
std::unique_ptr<MATLABEngine> matlabPtr = startMATLAB(optionVec);

Version History

Introduced in R2017b

expand all