Main Content

matlab::cpplib::initMATLABApplication

Start the MATLAB Runtime and initialize its application state

Description

std::shared_ptr<MATLABApplication> initMATLABApplication(matlab::cpplib::MATLABApplicationMode mode, const std::vector<std::u16string>& options = std::vector<std::u16string>())

matlab.cpplib.initMATLABApplication accepts as input mode and an optional array of startup options. It returns a shared pointer to a MATLABApplication object. The shared pointer is passed to the function matlab::cpplib::initMATLABLibrary, which returns a unique pointer to a user written library. This unique pointer is then used to call MATLAB® functions from the library

A process should call this method only once.

Parameters

MATLABApplicationMode mode

Mode in which to start application:

  • MATLABApplicationMode::IN_PROCESS

  • MATLABApplicationMode::OUT_OF_PROCESS

const std::vector<std::u16string>& options

Start up options used to start a MATLAB Runtime. They include:

  • -nodisplay: Starts the MATLAB Runtime without display functionality on Linux®.

  • -nojvm: Disables the Java® Virtual Machine, which is enabled by default.

  • -logfile filepath: Writes to the log file with path filepath. -logfile and filepath must be specified as separate consecutive arguments.

Return Value

std::shared_ptr<MATLABApplication>

Pointer to a MATLABApplication object that encapsulates the application state.

Exceptions

matlab::cpplib::ApplicationLaunchError

The function failed to start.

Examples

Start MATLAB Runtime In-Process, with Default Runtime Options

std::shared_ptr<MATLABApplication> appPtr = initMATLABApplication(MATLABApplicationMode::IN_PROCESS);

Start MATLAB Runtime Out-Of-Process, Without a Java Virtual Machine

std::vector<std::string> opts = {"-nojvm"};
std::shared_ptr<MATLABApplication> appPtr = initMATLABApplication(MATLABApplicationMode::OUT_OF_PROCESS, opts);

Start MATLAB Runtime In-Process, and Generate a Log File

std::vector<std::u16string> opts = {u"-logfile", 
						u"C:\\somepath\\matlab_app.log"};
std::shared_ptr<MATLABApplication> appPtr = initMATLABApplication(MATLABApplicationMode::IN_PROCESS, opts);

Version History

Introduced in R2018a