MATLAB: How to connect to an instance of MATLAB that is already running

actxgetrunningserverautomationcomenableserviceinstancesMATLABobjectoldrunningservertable

I would like to connect to an instance of MATLAB that is already running.

Best Answer

If an session of MATLAB has already been opened, you can use the MATLAB function "enableservice"
to MATLAB as an Automation Server. This can be recognized by the "actxGetRunningServer" command in other instances of MATLAB. To enable an instance as an Automation Server, you can execute the following command at the MATLAB Command Prompt:
state = enableservice('AutomationServer', true)
The "actxGetRunningServer" can be used as follows:
h = actxGetRunningServer('matlab.application')
This will allow you to connect to the already existing session of MATLAB.