MATLAB: Run a simulink model for a certain amount of time and pause

modelsimulationcommandsimulink

If there any way that you can run a simulink model from the command line for a certain amount of time, and then pause the model? I tried:
set_param(modelName,'SimulationCommand','Start');
But it runs the model for whatever times in the model EndTime dialog box (set to 10 seconds), before it leaves that line of code. If my time step is 250 m/s, is there anyway to tell the model to run for 1 second or 4 cycles and to pause? I know about:
set_param(modelName,'SimulationCommand','pause');
set_param(modelName,'SimulationCommand','continue');
But I can't get 'start' to do anything other than to run the full amount of time. Thanks.
EDIT –
Is there anyway to load/open a simulink model in into a paused state?

Best Answer

If you know the times that you want to stop and restart it at, could you maybe use the SimState to resume the simulation, something like this?
open('sldemo_bounce');
mdl = bdroot;
set_param(mdl, 'SaveFinalState', 'on', 'FinalStateName',...
[mdl 'SimState'],'SaveCompleteFinalSimState', 'on')
[t1, Y1] = sim(mdl, [0 15]);
plot(t1,Y1,'b');
set_param(mdl, 'LoadInitialState', 'on', 'InitialState',...
[mdl 'SimState']);
[t2, Y2] = sim(mdl, [15 25]);
hold on; plot(t2,Y2,'r');
set_param(mdl, 'LoadInitialState', 'off');