How to use the simulation time in MATLAB

1 Ansicht (letzte 30 Tage)
Moinul Shahidul Haque
Moinul Shahidul Haque am 7 Aug. 2019
Beantwortet: Fangjun Jiang am 8 Aug. 2019
Hello,
The way I am trying to simulate is like : Run a simulink model for 1 sec. pause the simulation, update the parameters and resume the simulation. I want to continue this cycle for 100 sec. I have used the following MATLAB commands
set_param('Model_Name','SimulationCommand','start') To start the simulation
set_param('Model_Name','SimulationCommand','pause') to pause the suimulation
set_param('Model_Name','SimulationCommand','update') to update the suimulation
set_param('Model_Name','SimulationCommand','continue') to resume the suimulation
Only problem I am facing is to pause the simulation after 1 sec. I try to use the clock in simulink and feed the output of the clock to the MATLAB using "To WorkSpace". it creates a vector. As a result, I could not use this time for my purpose.
In case, someone has solved this problem, I would greatly appreciate if you could kindly share your solution.
Thanks in advance

Antworten (1)

Fangjun Jiang
Fangjun Jiang am 8 Aug. 2019
Create a 1Hz trigger (e.g. Pulse Generator with amplitude of 1 and period of 1), feed it to a "Not" block and then an "Assertion" block. The simulation will pause automatically every 1 second.
Uncheck "Stop simulation when assertion fails". add the below lines as the simulation callback
set_param(...);
set_param('ModelName','SimulationCommand','update');
set_param('ModelName','SimulationCommand','continue');
Note that the Pulse Generator may trigger more pauses if the step size is less than 0.05. The point is to make a 1Hz trigger based on your simulation settings.

Kategorien

Mehr zu Event Functions finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by