How to run Simulation for certain amount of time

조회 수: 11 (최근 30일)
Peter Pallasch
Peter Pallasch 2021년 5월 11일
편집: Peter Pallasch 2023년 4월 26일
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.
  댓글 수: 5
Urveshkumar Dharmendrabhai
Urveshkumar Dharmendrabhai 2023년 4월 26일
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 2023년 4월 26일
편집: Peter Pallasch 2023년 4월 26일
"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!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Call MATLAB from Python에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by