Step Through Simulation
This example shows how to step through major time steps of a simulation while viewing signal values in the block diagram. In this example, you start the simulation by clicking Step Forward so the simulation pauses after the first major time step. You can also start stepping through a simulation after you pause by clicking Pause or after the simulation pauses on a breakpoint. When the simulation pauses on a breakpoint, additional stepping options are available that allow you to step through a time step block by block. For more information, see Debug Simulation Using Signal Breakpoints.
Open and Configure Model
Open the model
vdp, which implements the Van der Pol equation.
For more information about the model, see Van der Pol Oscillator.
You might run several simulations while analyzing and debugging your model. To save time by compiling the model only before the first simulation, enable fast restart. In the Simulink® Toolstrip, on the Simulation tab, click Fast Restart.
Add port value labels so you can see the signal values as you step through the
simulation. Click an empty area in the upper left of the canvas and drag to select
everything in the block diagram. Then, on the Debug tab, in the
Tools section, in the Port Values
button group, click Show port value label on selected signal
. The port value labels show
yet until the first forward step in simulation after you add the port
Step Forward One Step at a Time
When you want to run a simulation one step at a time from the beginning, you can
start the simulation by clicking Step Forward. In the
Simulink Toolstrip, on the Simulation tab, click
Step Forward to start a simulation of the model
vdp. The simulation starts and pauses just after calculating
the output values for the first simulation time and before stepping to the next
To monitor the simulation status and simulation time, use the status bar at the bottom of the Simulink Editor. In the middle of the status bar, the software displays the time of the last major time step and a progress bar that indicates the simulation status. Some solvers perform calculations to determine the time of the next major time step before the point in the simulation loop where the simulation pauses when you click Step Forward. In this case, the solver is ahead in simulation time relative to the block diagram. The software adds an asterisk to the simulation time to indicate that the solver has moved ahead in simulation time.
Each time you click Step Forward, the simulation advances one major time step. The time in the status bar updates, and the port value labels update to display the new signal values.
Step Forward Multiple Time Steps at a Time
To advance the simulation by multiple time steps each time you click
Step Forward, configure the simulation stepping options. To
open the Simulation
Stepping Options dialog box, click the Step Back
button arrow then select Configure Simulation Stepping. In the
Simulation Stepping Options dialog box, specify Move back/forward
5. Then, click
Now, when you click Step Forward again, the simulation advances through five major time steps. The time changes by a larger increment, and you can see the overall simulation progress indicated in the status bar.
Double-click the Scope block. The plot updates to display the data
for the signals
x2 as the simulation
advances. Click Step Forward to see the Scope
block update to display data from five more time steps.
Step Back in Simulation
Before you can step back in simulation, you have to enable stepping back. To support stepping back in simulation, the software captures snapshots of the model operating point while advancing forward in simulation. Capturing these snapshots requires memory and can affect simulation performance. For more information, see How Stepping Through Simulation Works.
Open the Simulation Stepping Options dialog box. Click the Step Back button arrow then select Configure Simulation Stepping. In the Simulation Stepping Options dialog box, select Enable stepping back then click OK.
Because stepping back was not enabled at the start of simulation, the software does not have a snapshot from a prior time in the simulation. Before you can step back, you must step forward. You cannot step back to a simulation time before the time you enabled stepping back.
Click Step Forward twice. Then, click Step Back. In the status bar, the simulation time updates to reflect the step back. The port value labels also update to display the value from the time to which you stepped back.
When you click Step Back a second time, the software disables the Step Back button because you cannot step back farther in this simulation.
Finish or Stop Simulation
When you are done stepping through the simulation, you can continue the simulation until the end or stop the simulation at the current time step.
To run the simulation through the simulation stop time, in the Simulation tab, click Continue.
To stop the simulation at the current time step, in the Simulation tab, click Stop.