How to run Simulation for certain amount of time

2 views (last 30 days)
i want to run my Simulation for a certain amount of time and then pause it. I tried with an assertion block which works fine but if i start the simulation through python the assertion block doesn't stop the simulation. Is there a work around?
kind regards

Accepted Answer

Fangjun Jiang
Fangjun Jiang on 11 May 2021
Specify the start time and stop time either directly through numerical value, or through variables and then set the value for the variables.
Peter Pallasch
Peter Pallasch on 11 May 2021
First thank you for your help!
Actually it was very hard to find something on this topic. I was seaching for days but i found an article. For everyone who has the same problem. You just start/pause the Simulation by setting the parameters directly. No need for the sim command.
Here is my example code:
eng = matlab.engine.start_matlab("-desktop")
eng.eval("model = '{}'".format("modelname"),nargout=0)
print("Initialized Model")
#Start Simulation and then Instantly pause
while True:
Here is a link to the article that helped me. The guy build a little controller to control the simulation via python:

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!