Main Content

Run a Simulation Step by Step

The Simulink® debugger provides functions you can use to advance a simulation from the method where it is currently paused by various increments. For example, you can advance the simulation:

  • Into or over the next method

  • Out of the current method

  • To the top of the simulation loop

After each advance, the debugger displays information that enables you to determine the point to which the simulation has advanced and the results of advancing the simulation to that point.

For example, after each step command, the debugger highlights the current method call stack in the Simulation Loop pane. The call stack comprises the next method and the methods that invoked the next method directly or indirectly.

When you debug simulations programmatically, use the where function to display the method call stack.

Block Data Output

After executing a block method, the debugger prints some or all of the following block data in the Output panel:

  • Un = vnth block input value

  • Yn = vnth block output value

  • CSTATE = v — Block continuous state vector

  • DSTATE = v — Block discrete state vector

The debugger also displays the current time, the ID and name of the next method to be executed, and the name of the block to which the method applies in the MATLAB® Command Window. The following example illustrates typical Simulink debugger outputs after a step command.

Stepping Commands

When you debug a model programmatically, use these commands to advance a simulation incrementally.

CommandStepping Behavior
step [in into]

Steps into the next method, stopping at the first method in the next method or, if the next method does not contain any methods, at the end of the next method

step over

Steps to the method that follows the next method, executing all methods invoked directly or indirectly by the next method

step out

Steps to the end of the current method, executing any remaining methods invoked by the current method

step top

Steps to the first method of the next time step

step blockmth

Steps to the next block method to be executed, executing all intervening model- and system-level methods


Same as step over

From the user interface, use the buttons in the toolbar to step through the simulation.

Clicking a button has the same effect as entering the corresponding command.

Continuing a Simulation

When you start the debugger from the Simulink Toolstrip, the Stop button turns red when the debugger pauses the simulation for any reason. To continue the simulation, click the Start/Continue button. When you debug a model programmatically, enter continue to continue the simulation. By default, the Simulink debugger runs the simulation to the next breakpoint or to the end of the simulation, whichever comes first.

Running a Simulation Nonstop

The run function runs a simulation to the end of the simulation, skipping any intervening breakpoints. At the end of the simulation, the Simulink debugger returns you to the MATLAB Command Prompt. To continue debugging a model, you must restart the debugger.


The user interface does not provide a graphical version of the run command. To run the simulation to the end, clear all breakpoints and then click Start/Continue.

Related Topics