MATLAB Answers

0

How to use the simulation time in MATLAB

Asked by Moinul Shahidul Haque on 7 Aug 2019
Latest activity Answered by Fangjun Jiang on 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

  0 Comments

Sign in to comment.

1 Answer

Answer by Fangjun Jiang on 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.

  0 Comments

Sign in to comment.