主要内容

matlab::engine::runMacLoopInProcess

Run in-process MATLAB on Mac

Since R2026a

Description

int runMacLoopInProcess(std::function<int(int, char*[])> func, int argc, char *argv[], const std::vector<std::u16string>& options = std::vector<std::u16string>())

Use runMacLoopInProcess to run MATLAB® on Mac platforms when you start MATLAB and the C++ engine in the same process using the MATLABApplicationMode::IN_PROCESS mode of matlab::engine::startMATLAB or matlab::engine::startMATLABAsync. On Mac platforms, in-process mode requires MATLAB to run on the main thread of the process. runMacLoopInProcess starts MATLAB on this main thread and runs your application logic on a secondary thread.

Include

Namespace:

matlab::engine
IncludeMatlabEngine.hpp

Parameters

std::function<int(int, char*[])> func

Function containing your application logic, including the call to startMATLAB(MATLABApplicationMode::IN_PROCESS). The function must be convertible to a function pointer. runMacLoopInProcess does not support lambda expressions that capture variables from the surrounding scope.

int argc

Number of command-line arguments. Copy this argument from the main function in your C++ engine application file.

char *argv[]

Command-line arguments array. Copy this argument from the main function in your C++ engine application file.

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

(Optional) MATLAB startup options. runMacLoopInProcess uses these options when starting MATLAB. Any startup options passed to startMATLAB inside func have no effect.

Return Value

int

The return value of func.

Exceptions

matlab::engine::EngineException

You call startMATLAB with MATLABApplicationMode::IN_PROCESS on Mac without using runMacLoopInProcess.

Examples

expand all

Use runMacLoopInProcess to start in-process MATLAB on Mac.

#include "MatlabEngine.hpp"

int appCode(int argc, char *argv[]) {
    using namespace matlab::engine;
    std::unique_ptr<MATLABEngine> matlabPtr = startMATLAB(MATLABApplicationMode::IN_PROCESS);
    // Application code here
    return 0;
}

int main(int argc, char *argv[]) {
    return matlab::engine::runMacLoopInProcess(appCode, argc, argv);
}

Version History

Introduced in R2026a