Main Content

matlab::engine::connectMATLABAsync

Connect to shared MATLAB session asynchronously

Description

FutureResult<std::unique_ptr<MATLABEngine>> connectMATLABAsync()

FutureResult<std::unique_ptr<MATLABEngine>> connectMATLABAsync(const matlab::engine::String& name)

Connect asynchronously to a shared MATLAB® session on the local machine.

  • If you specify the name of a shared MATLAB session, but the engine cannot find a session with that name, the engine throws an exception.

  • If you do not specify a name and there is no shared MATLAB session available, the engine starts a new shared MATLAB session. The MATLAB desktop is not started.

  • If you do not specify a name and there are shared MATLAB sessions available, the engine connects to the first available session.

Include

Namespace:

matlab::engine
IncludeMatlabEngine.hpp

Parameters

const matlab::engine::String& name

Name of the shared MATLAB session

Return Value

FutureResult<std::unique_ptr<MATLABEngine>>

A FutureResult object that you can use to get the pointer to the MATLABEngine

Examples

expand all

Connect to a shared MATLAB session named my_matlab asynchronously. Use the FutureResult get method to retrieve the pointer to the MATLABEngine object.

#include "MatlabEngine.hpp"
void asyncConnect() {
    using namespace matlab::engine;

    // Find and connect to shared MATLAB session
    FutureResult<std::unique_ptr<MATLABEngine>> future = connectMATLABAsync(u"my_matlab");
    ...
    std::unique_ptr<MATLABEngine> matlabPtr = future.get();
}

Version History

Introduced in R2017b