How to run Simulation for certain amount of time

15 views (last 30 days)
Hello,
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.
  5 Comments
Urveshkumar Dharmendrabhai
Thank you for your answer. Would you please clarify what is a
time
in your answer? How and where have you defined 'time' variable?
Peter Pallasch
Peter Pallasch on 26 Apr 2023
Edited: Peter Pallasch on 26 Apr 2023
"time" is not a variable. Its a python module if you refere to the line of code:
import time
time.sleep(30)
The whole point of this Setup was to discretize time. Hence you start your matlab simulation via:
eng.set_param("modelname",'SimulationCommand','continue',nargout=0)
use the python time module to wait 30 seconds by using the python time module via:
import time
time.sleep(30)
and then stop the simulation again via:
eng.set_param("modelname",'SimulationCommand','pause',nargout=0)
Then you can make calculations with the collected data and you have descrete time where every timestep is equal to about 30 secs. The whole thing is controlled via python. Matlab has a python library for that purpose which is included as python module via:
import matlab.engine
All code shown here is no matalb code. I also updated the example code which i think you were refering to. I hope this helps!

Sign in to comment.

More Answers (0)

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!