MATLAB Answers

How to run Simulation for certain amount of time

4 ビュー (過去 30 日間)
Peter Pallasch
Peter Pallasch 2021 年 5 月 11 日
コメント済み: Peter Pallasch 2021 年 5 月 11 日
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

採用された回答

Fangjun Jiang
Fangjun Jiang 2021 年 5 月 11 日
Specify the start time and stop time either directly through numerical value, or through variables and then set the value for the variables.
  3 件のコメント
Peter Pallasch
Peter Pallasch 2021 年 5 月 11 日
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:
sys.path.append("c:\work\matlab19bPy36")
eng = matlab.engine.start_matlab("-desktop")
eng.run(nargout=0)
eng.eval("model = '{}'".format("modelname"),nargout=0)
eng.eval("load_system(model)",nargout=0)
print("Initialized Model")
#Start Simulation and then Instantly pause
eng.set_param("modelname",'SimulationCommand','start','SimulationCommand','pause',nargout=0)
while True:
eng.set_param("modelname",'SimulationCommand','continue',nargout=0)
print("Continue")
time.sleep(30)
eng.set_param("modelname",'SimulationCommand','pause',nargout=0)
print("stopped")
time.sleep(30)
Here is a link to the article that helped me. The guy build a little controller to control the simulation via python:

サインインしてコメントする。

その他の回答 (0 件)

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by