Control Matlab COM Automation Server instance from other Matlab instance

Hello, I am wondering if it is possible to register one Matlab instance with the Automation Server, and then control this registered instance from a second Matlab instance. In the documentation there is only code for applications/languages, but not Matlab.
Best Regards,
Silvan

 Accepted Answer

Hello,
You can register one MATLAB instance and can create a COM server of it from another MATLAB instance.
To register MATLAB as an automation server, refer the below link:
Then, call it from other MATLAB instance:
a = actxserver('Matlab.Application')

4 Comments

Thank you for your response Amit! Works great.
Just for other people who might have the same question, after getting the handle to the other matlab instance with the actxserver() command, you can do things on the other matlab instance by using the commands on this site: https://ch.mathworks.com/help/matlab/call-matlab-com-automation-server.html
If you click on a specific command, there is a line "MATLAB Client". You'll have to use this command in matlab to control the second instance.
can you please tell me how to do it.as theres nothing like Matlab client at that path there and i am trying to do same thing as you mentioned.
Below is my version of how to control a Simulink model (Modelname.slx) from another Matlab instance via the Appdesigner. The Appdesigner file is run in the main Matlab instance.
%the code below is inside the startup function of the appdesigner file
rehash path
app.runDirectory = strrep(string(pwd),'\','/'); % to get the path right
% Start second matlab instance
!matlab -nodesktop -r regmatlabserver &
app.inst2 = actxserver('Matlab.Application'); % inst2 must also be set as a property in appdesigner
command = "open '" + app.runDirectory + "\Modelname.slx'";
Execute(app.inst2,command); %this opens the second instance and the model Modelname.slx
MinimizeCommandWindow(app.inst2); % calling a second instance opens command windows that might be disturbing
Then you can control the simulink model in the typical fashion, with the exception of specifiying the 2nd instance:
command1 = "set_param('Modelname', 'SimulationCommand', 'start')"; % construct start command
Execute(app.inst2,command1); %run the model
Please note: Calling a 2nd instance requires administrator privileges. You might want to permanently allow Matlab to be run with those privileges.
thank you got my thing working..
Also is there any other way to control multiple matlab instances(Slaves) from one instance(Master)?
As with COM server we can only control one matlab from other instances of matlab

Sign in to comment.

More Answers (0)

Asked:

TZ
on 31 Aug 2017

Commented:

on 21 May 2020

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!