How to run Simulation for certain amount of time

11 vues (au cours des 30 derniers jours)
Peter Pallasch
Peter Pallasch le 11 Mai 2021
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

Réponse acceptée

Fangjun Jiang
Fangjun Jiang le 11 Mai 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 commentaires
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 le 26 Avr 2023
Modifié(e) : Peter Pallasch le 26 Avr 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!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Call MATLAB from Python dans Help Center et File Exchange

Produits


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by