Stepwise Call of Simulink Simulation from Python

3 Ansichten (letzte 30 Tage)
Hans-Joachim Steinort
Hans-Joachim Steinort am 27 Aug. 2021
Beantwortet: surya venu am 3 Apr. 2024
We are currently trying to accomplish a circulating data flow with python and simulink like this:
  1. The simulation starts from a defined initial point and calculates one simulation step
  2. Variables of interest are sent as output to an external module (e.g. a machine learning model in python)
  3. The external module processes these outputs and generates a new set of variables
  4. The new set of variables is sent back as input to the simulation
  5. The loop starts over from point 1 with the new variables set until the simulation reaches the maximum of the simulation duration or generates outputs corresponding to a terminal condition
We are aware that Matlab provides great toolboxes (e.g. the Reinforcement Learning Toolbox which we already use), yet we have algorithms which we do not want to port or rebuild with said toolboxes.
In the Video MATLAB and Simulink with Python your colleague shows a possibility in which the external module is indirectly implemented within the Simulink model and called as a slave. But what we are trying to do is to make the external module the master of this construct.
We know that the MATLAB Engine API for python allows to start a simulation like
>>>import matlab.engine
>>>eng = matlab.engine.start_matlab()
>>>eng.sim("vdp")
The open question is:
Does the matlab engine allow to run the simulation stepwise like it's needed for the aforementioned data flow?
Thanks in advance for your time and effort.

Antworten (1)

surya venu
surya venu am 3 Apr. 2024
Hi,
The MATLAB Engine API for Python facilitates running MATLAB code and functions from Python, but it may face limitations in executing simulations stepwise, as needed in your scenario.
While it allows for the execution of MATLAB commands and scripts within Python, it might not support detailed control over each step of a simulation directly from Python.
The API is generally used for integrating MATLAB code into Python scripts without offering precise control over simulation processes.
Hope it helps.

Kategorien

Mehr zu Call MATLAB from Python finden Sie in Help Center und File Exchange

Produkte


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by