How to use the simulation time in MATLAB
4 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(1 个)
Fangjun Jiang
2019-8-8
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Event Functions 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!