Clear Filters
Clear Filters

Open a 2nd Matlab session and read model-file open in the 1st session (programatically)

2 views (last 30 days)
I have a unique situation where I need to programatically open a 2nd session of Matlab and run a script. That is easy enough. However, I need this script to check for some info in the 1st session. For example, return the current path in the first session, return a list of all the Simulink models open in the first session, maybe even rename some signals in one of the models in session 1. This I have no idea how to do.
I've read a bit about UDP, doesn't look like that would work for my use-case. Any suggestions welcome. Thanks.
J

Answers (1)

Animesh
Animesh on 10 Jun 2024
Interacting between two MATLAB sessions can be quite complex, but there are a few approaches you might consider:
  1. MATLAB Engine API for Python: If you’re comfortable with Python, you could use the MATLAB Engine API to connect to a running MATLAB session from Python. You can share the MATLAB Engine session by typing matlab.engine.shareEngine in the first MATLAB session. Then, from Python, you can connect to this shared session and execute commands or scripts.
  2. MATLAB Automation Server: On Windows, you can start MATLAB with the '-automation' flag which allows you to attach an engine program to a MATLAB session that is already running. This could potentially be used to interact with the first session from the second one.
  3. File-based Communication: A more straightforward approach might be to use file-based communication. The first session could write the required information to a file, and the second session could read from this file. This method is less elegant but can be easier to implement.

Categories

Find more on Event Functions in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!