MATLAB: Is there a command line way to step forward and backward in the Simulink model in the same way that the Simulation stepper allows me to do in the toolstrip.

simulink

I understand that I can use the Simulation stepper interface to step forwards and backwards in my Simulink model. Is there a command line alternative to do this ?

Best Answer

There is no direct method of doing this. However, there are a few workarounds. 
1. This method works only from MATLAB R2013b and future releases. 
Use the command line to execute the following lines :
>> set_param(OBJECT, 'SimulationCommand', 'start', 'SimulationCommand', 'pause'); %Takes the simulation to time t = 0.0 and pauses it
>> set_param(OBJECT, 'SimulationCommand', 'continue', 'SimulationCommand', 'pause'); %Runs the simulation for 1 time step and pauses it 
where OBJECT is the model or block object on which to apply the simulation. 
2. A more consistent method for stepping forward in fixed time-steps would be to use the "step top" command in the Simulink Debugger mode. 
Use the command line to execute the following:
>>sldebug('MODEL_NAME') %Start the simulation in debug mode for the model named MODEL_NAME. Takes simulation to t=0.0 and pauses it
(sldebug@0:) >> step top %Finishes all the initialization parts of the simulation
(sldebug@0:) >> step top %Runs the simulation for 1 time step and pauses it 
There does not seem to be a method for stepping backwards in time.