How to opening 1 instance of MATLAB from MATLAB, but accessing it multiple times
Show older comments
Hello,
I would like to do the followings:
- From a MATLAB session, open another instance of MATLAB - which can be done by: !matlab &
- Every now and then from existing MATLAB session have a command executed in the other session. This is the part that I do not know how to do. How in existing MATLAB session, I can have a command exscuted on another instance I already opened.
I greatly appreciate your suggestions.
3 Comments
Walter Roberson
on 17 Aug 2021
Which operating system? The techniques differ with operating system and I do not feel like writing them all up.
Ali Razavi
on 17 Aug 2021
Raymond Norris
on 17 Aug 2021
Does the second MATLAB have to have its Desktop visible to interact with or does it suffice to be running in "headless" mode?
Do you have the Parallel Computing Toolbox?
Accepted Answer
More Answers (2)
Ali Razavi
on 18 Aug 2021
Edited: Ali Razavi
on 18 Aug 2021
0 votes
Walter Roberson
on 18 Aug 2021
0 votes
As you are using Windows, one approach is to use .NET System.Diagnostics.Process https://www.mathworks.com/matlabcentral/answers/586706-how-to-redirect-standard-input-and-standard-output-using-net-system-diagnostics-process#answer_487475 to open a process connection, and write commands to the other MATLAB. The link shows how to redirect input and output.
Another possibility is to invoke MATLAB through actxserver() and use the Automation Engine facilities; https://www.mathworks.com/help/matlab/call-matlab-com-automation-server.html
1 Comment
Jon
on 9 May 2024
Hello @Walter Roberson
I am trying to do something similar to what the OP has asked about. I do not have the Parallel Processing toolbox, and so was interested in your alternative suggestions.
First let me describe what I would like to accomplish. I am running MATLAB (R2024a) Update 2 on a Windows 10 computer.
- Open a first instance of MATLAB in the usual way from the Window desktop
- From the first instance of MATLAB open a second instance of MATLAB (ideally without another user interface opening up)
- From first instance of MATLAB tell second instance of MATLAB to run a .m file
- Use the first instance of MATLAB interactively for some time (1 hour or more)
- From the first instance of MATLAB tell the second instance of MATLABt to run a .m file
- From the first instance of MATLAB tell the second instance of MATLAB to run the quit command
I see that you suggest that this could be done using either a com server or .Net. I looked into the com server approach, but will have difficulties with that, because in our corporate installation, it is difficult to obtain needed administrative privileges.
I am therefore most interested in the .Net approach. Googling this I see some general mentions that this could be used for my use case, but as I don't know anything about .Net I'm not really sure where to start.
If you could provide any further specific hints, or useful links that specifically address my main need which is to tell the second instance of MATLAB to run a .m file I would be very appreciative. Thanks
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!