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

3 vues (au cours des 30 derniers jours)
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

Réponses (1)

Animesh
Animesh le 10 Juin 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.

Catégories

En savoir plus sur Startup and Shutdown dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by