Simulation Stepping Options - Enable stepping back and configure number of time steps to move when stepping
through simulation - MATLAB ([original](https://in.mathworks.com/help/simulink/slref/simulationsteppingoptions.html)) ([raw](?raw))
Enable stepping back and configure number of time steps to move when stepping through simulation
Description
Use the Simulation Stepping Options dialog box to configure how many major time steps the simulation moves when you click Step Forward orStep Back and to enable stepping back. You can step backward in time in a simulation only after you enable stepping back using the Simulation Stepping Options.
You can adjust the simulation stepping options during simulation to balance simulation performance against the granularity of steps based on the runtime behavior of the system. For more information, see How Stepping Through Simulations Works.
Rapid accelerator simulations do not support stepping forward or backward. To step through a simulation, use normal or accelerator mode. When you want to use low-level debugging capabilities, such as stepping block by block, use normal mode.
For an example that shows all the options available for stepping through simulations, seeStep Through Simulations Using the Simulink Editor. The table summarizes when and how you can use buttons in the Simulink® Toolstrip to control the simulation execution.
Stepping Option | Description | Keyboard Shortcut | Availability |
---|---|---|---|
Continue![]() |
Continue simulation. | Ctrl+T or F5On macOS, press command (⌘) instead of Ctrl. | Always available. |
Step Forward![]() |
Advance the simulation by one or more time steps. | — | |
Step Back![]() |
Step simulation back by one or more time steps.To use this option, you must enable stepping back. For more information, see Simulation Stepping Options. | — | Available only when you enable stepping back using the Simulation Stepping Options dialog box. |
Step Over![]() |
Advance simulation to just before the next block executes. | F10 _(since R2023b)_OnmacOS, pressShift+Command+O. | Available before starting a simulation and when a simulation is paused if Pause within time step is enabled in the Breakpoints List. (since R2024b) In R2024a: Available while simulation is paused if Pause within time step is enabled and the model has at least one active breakpoint. Before R2024a: Available only while paused within a time step. |
Step In![]() |
Step into Model block, atomic subsystem, MATLAB Function block, or Stateflow® chart.When the next block to execute is not aModel block, atomic subsystem, or MATLAB Function block and the simulation is not paused on a Stateflow chart, the Step In button takes the same action as the Step Over button. | F11 _(since R2023b)_OnmacOS, pressShift+Command+I. | Available only when paused within a time step. |
Step Out![]() |
Steps out of Model block, atomic subsystem, or Stateflow chart.When the next block to execute is not aModel block or atomic subsystem and the simulation is not paused on a Stateflow chart, the Step In button takes the same action as the Step Over button. | Shift+F11 _(since R2023b)_On macOS, pressShift+Command+U. |
Open the Simulation Stepping Options
- Simulink Toolstrip: On the Simulation tab or theDebug tab, click the Step Back button.
- Simulink Toolstrip: On the Simulation tab or theDebug tab, click the Step Back button arrow and select Configure Simulation Stepping.
Examples
- Step Through Simulations Using the Simulink Editor
- How Stepping Through Simulations Works
- Debug Simulation Using Signal Breakpoints
- View Signal Values Using Port Value Labels
Parameters
Select this option to enable stepping backward as well as forward in time during simulation. When you select this option, you can configure how the software saves data during simulation to support stepping back.
Specify how many simulation snapshots to save to support stepping back. A simulation snapshot contains all the information required to restore the state of the simulation.
Simulation snapshots are stored in memory and are not accessible in the workspace during or after simulation. Saving more snapshots increases the amount of memory the simulation uses and can slow the speed of the simulation.
Dependencies
To enable this parameter, select Enable stepping back.
Specify the number of major time steps between each simulation snapshot the software saves to support stepping back.
Dependencies
To enable this parameter, select Enable stepping back.
Specify the number of major time steps to step through each time you press theStep Forward or Step Back button.
Tips
- To inspect signal values while stepping through the simulation, display port value labels on signals. Select a signal. Then, on the Debug tab, underTools, in the Output Values button group, click Show Output Value of selected signal
.
- To start stepping through a normal or accelerator mode simulation that is already running, pause the simulation. Then, use the Step Forward andStep Backward buttons.
- To start stepping from a specific time within a simulation, specify a pause time. On the Debug tab, under Breakpoints, specify thePause Time in seconds. When you start the simulation by clickingRun, the simulation runs until the specified time and pauses. From there, you can step through the simulation.
- To debug the behavior of a model around a point of interest, you can add a signal breakpoint and specify the condition such that the simulation pauses at the time of interest. Then, use the Step Forward and Step Backward buttons. For more information about setting breakpoints in your model, see Breakpoints List.
- The stepping and breakpoint options in the Simulink Editor do not have a direct programmatic equivalent available in the software. The Simulink debugging programmatic interface includes options for setting breakpoints and stepping through simulations. However, the behavior of these functions is not identical to the behavior of the stepping options in the Simulink Editor. For more information about programmatic debugging, see Simulink Debugging Programmatic Interface.
Version History
Introduced in R2012b
Enabling stepping back in simulation has a smaller effect on simulation performance. To support stepping back in simulation, the software captures simulation snapshots, which adds overhead and can slow simulation. The performance improvement for simulations with stepping back enabled varies between models, with smaller improvements for models that use certain blocks and features, including:
- Referenced models configured to simulate in accelerator mode
- Simscape™ blocks
- S-functions that implement custom methods for saving and restoring the S-function operating point
You can assess the performance improvement for a model by running equivalent simulations of the model in R2022b and R2023a with back stepping enabled and checking the execution time in the simulation metadata. For example, to assess the performance improvement for the modelslexAircraftExample
, follow these steps using R2022b and then R2023a:
- Open the model.
openExample(...
"simulink_aerospace/AircraftLongitudinalFlightControlExample",...
supportingFile="slexAircraftExample") - To capture timing information in the simulation metadata, including the time spent in the execution phase of the simulation, check that the Single simulation output parameter is enabled.
In the Simulink Toolstrip, on the Modeling tab, clickModel Settings. On the Data Import/Export pane, select Single simulation output. - Enable stepping back.
On the Simulation tab, click Step Back. In the Simulation Stepping Options dialog box, select Enable stepping back. - In the Simulation Stepping Options dialog box, check that the Maximum number of saved back steps and Interval between stored back steps parameters both use the default value of
10
. Then, click OK. - Use the same start and stop times for the simulation in R2022b and R2023a. For this simulation, use a stop time of 1000 seconds.
On the Simulation tab, in the Stop time field, enter1000
. - To run the simulation, on the Simulation tab, clickRun.
- Check the execution time in the simulation metadata captured in the simulation output.
execTime = out.SimulationMetadata.TimingInfo.ExecutionElapsedWallTime;
The table summarizes performance improvements for two example models by comparing the execution time between simulations run in R2022b and R2023a. The modelasbhl20
shows a smaller performance improvement because the model uses features that involve custom operating point implementations, including a referenced model that simulates in accelerator mode. The simulations were timed on a Windows® 10, AMD® EPYC 74F3 @ 3.19 GHz test system.
For more information about how stepping back and the simulation stepping options affect simulation performance, see How Stepping Through Simulations Works.