How Stepping Through Simulation Works
The parameter values you specify in the Simulation Stepping Options dialog box affect how the software:
Advances the simulation when you click Step Forward or Step Back
Captures snapshots of the model operating point to support stepping back
When you step forward in simulation, the software continues the simulation. However, when you step backward, the software does not simulate the model in reverse. To support stepping backward in a simulation, the software captures snapshots of the model operating point as you simulate the model. When you click Step Back, the software restores the model operating point from one of the snapshots.
The software collects simulation snapshots for stepping back only when stepping back is enabled. When you enable stepping back for a simulation that is in progress, you must step forward before you can step back, and you cannot step back to a point in the simulation before you enabled stepping back.
The simulation snapshots contain the same model operating point information that is logged when you select Save final operating point on the Data Import/Export pane of the Configuration Parameters dialog box. The software captures the model operating point information in the simulation snapshots only to support stepping back. The simulation snapshots the software captures for stepping back are not accessible during or after simulation. For more information about saving the model operating point, see Save Block States and Simulation Operating Points.
The Move back/forward by parameter specifies the number of
major time steps to advance the simulation each time you click Step
Forward. The image illustrates how the simulation advances based on
whether the Move back/forward by option is specified as
At the start of the simulation, State 0, the parameter value is
2. When you click Step Forward, the simulation advances through State 1 and pauses on State 2.
While paused after the second major time step, suppose you change the parameter value to
1. Now, when you click Step Forward, the simulation advances to State 3, which corresponds to the next time step.
Suppose you change the parameter value back to
2while paused after the fourth major time step. Now, when you click Step Forward, the simulation advances to State 6.
Capturing Simulation Snapshots
The simulation snapshots that the software collects for stepping backward contain all the information required to continue the simulation from the point at which the snapshot was taken. Collecting the snapshots requires memory and can affect simulation performance. When you configure the simulation stepping options, you can specify:
Maximum number of saved back steps — Total number of snapshots to save
Interval between stored back steps — Number of simulation time steps to skip between saving snapshots
Saving a smaller number of total time steps and skipping steps between snapshots can mitigate the effect that enabling stepping back has on simulation performance.
The simulation stepping options for saving snapshots are independent of the Move back/forward by option, which controls how the simulation advances when you click Step Forward or Step Back.
The image illustrates how snapshots are captured when the Interval
between stored back steps parameter value is
The software captures a snapshot at the start of the simulation, after the third
major time step, and after the sixth major time step.
You can change the interval between snapshots during simulation when you need to
advance the simulation by smaller increments to analyze a point of interest. For
example, the image illustrates how the simulation in the previous image would
capture snapshots if you changed the interval between snapshots from
The software captures a snapshot of State 0 at the start of the simulation.
After three major time steps, the software captures a snapshot of State 3.
While paused on State 3, you change the value of the Interval between stored back steps parameter from
The software captures a snapshot of the simulation state for each major time step through State 6.
The way the software steps back in simulation depends on whether a snapshot exists for the time to which you step back.
When a snapshot exists for the time step, the software restores the model operating point contained in the snapshot.
When a snapshot does not exist for the time step, the software restores the model operating point from the last snapshot before the time step then simulates forward
For example, suppose you are paused after the sixth time step in a simulation that:
Captures a snapshot of the model operating point every three time steps
Steps backward by one time step each time you click Step Back
When you click Step Back, the software restores the snapshot captured after the third time step and simulates forward two time steps to pause after the fifth time step.
You can modify the values of tunable parameters while paused during simulation. The software applies the new parameter value for the next forward step in simulation. Depending on how you configure the simulation stepping options, the next forward step in simulation might happen when you click Step Back.
Pausing on Breakpoints
When your model contains enabled breakpoints, the simulation pauses on the breakpoint if the condition for the breakpoint is met in the process of stepping forward. The software ignores breakpoints when stepping backward.
By default, the software is configured to pause within a time step as soon as the condition for a breakpoint is met. When you click Step Forward while paused on a breakpoint, the simulation advances through the current time step. When you click Step Back, the software steps back to the start of the current time step. For more information, see Breakpoints List.
Additional Considerations for Stepping Through Simulation
Not all blocks, features, and model configurations support stepping back in simulation. Lack of support for stepping back does not interrupt a simulation. The software issues a warning when a model with stepping back enabled does not support stepping back.
Because stepping back relies on the functionality for saving the model operating point, stepping back is supported only for models that support saving the model operating point. For more information, see Additional Considerations for Saving and Restoring Model Operating Points.
The table summarizes other considerations related to stepping back in simulation for several blocks and modeling constructs.
|Feature or Modeling Pattern||Considerations for Stepping Back|
If you modify the simulation stepping options for a referenced model during simulation, the same options change in the top model. When the simulation completes, the simulation stepping options for referenced models revert to their values before the simulation. The simulation stepping options for the top model stay the same as they were at the end of the simulation.
The visualizations in these blocks do not update to reflect the result of stepping back:
MATLAB Function blocks
The simulation state after stepping back might be incorrect for models that contain MATLAB Function blocks that call C code that contains static variables or has side effects, such as writing to a file.