Main Content

Simulation Pacing Options

Slow simulation to a specified ratio of simulation time to wall clock time

Description

Use simulation pacing to slow simulation to help analyze and interact with your model. When you pace the simulation, visualizations such as Scope blocks and dashboard blocks update at the slower rate. With simulation pacing enabled, you can modify parameters in the model and observe the effect of the change in the model.

Simulation pacing can be useful in models where the software computes the results for a second of simulation time in a few milliseconds of clock time.

The Simulation Pacing Options dialog box

Open the Simulation Pacing Options

In the Simulink® Toolstrip, on the Simulation, Debug, or Modeling tab, click the Run button arrow. Then, select Simulation Pacing.

Examples

expand all

Open the model vdp.

mdl = "vdp";
open_system(mdl)

The model vdp.

Simulate the model.

out = sim(mdl);

The simulation completes in just a few seconds.

simMeta = getSimulationMetadata(out);
simMeta.TimingInfo.TotalElapsedWallTime
ans = 17.0290

To better observe how the signal values change during simulation, enable simulation pacing.

  1. In the Simulink® Toolstrip, on the Simulation tab, click the Run button arrow, then select Simulation Pacing.

  2. In the Simulation Pacing Options dialog box, select Enable pacing to slow down simulation.

Alternatively, use the set_param function to enable simulation pacing.

set_param(mdl,"EnablePacing","on")

The icon for the Run button icon is annotated with a clock to indicate that simulation pacing is enabled.

To view the signals x1 and x2 during the paced simulation, double-click the Scope block.

Simulate the model again. On the Simulation tab, click Run. Alternatively, use the sim function.

out = sim(mdl);

The Scope block updates to display the data for the signals x1 and x2 as the simulation runs.

The Scope block displays data through the current simulation time of approximately 7 seconds.

While a paced simulation runs, you can modify block parameters, add and remove port value labels, and navigate through a model hierarchy the same way you can during a simulation without pacing. You can also enable or disable simulation pacing and adjust the pacing rate during simulation.

For example, run another paced simulation and change the value of the Gain parameter for the block named Mu during the simulation. For this simulation, decrease the ratio of simulation time to wall clock time to ensure you have sufficient time to modify the parameter and see the effect of the change in the Scope block.

  1. In the Simulation Pacing Options dialog box, drag the value slider or enter a value in the field to decrease the simulation pace to an approximate ratio of 0.35 seconds of simulation time per second.

  2. In the Simulink Toolstrip, on the Simulation tab, click Run.

  3. Double-click the block named Mu.

  4. Use the slider in the custom Block Parameters dialog box for the masked block to adjust the value of the Gain parameter. Monitor the effect of changing the Gain parameter on the signals x1 and x2 in the Scope block.

The Scope block displays the data for signals x1 and x2 through the current simulation time of approximately 11 seconds. The shape and amplitude of the signals change due to the changing gain value.

You can use dashboard blocks to view signals and tune variable and parameter values in your model while slowing a simulation using simulation pacing. Using dashboard blocks with simulation pacing allows you to build an intuitive understanding of your model and how the model responds to changes as you tune parameters in your model.

The example model uses simulation pacing to slow the simulation pace to approximately equivalent to wall clock time, or one simulation second per wall clock second. The model has a button labeled Signal Select that you can use to control whether the sine wave or sawtooth input signal passes to the output, which is visualized using a Dashboard Scope block.

Open the model and run a simulation. During the simulation, press and release the Signal Select button and observe the effect on the output signal.

For more information about creating the example model, see Control Merging Signals with the Push Button Block.

Related Examples

Parameters

expand all

Option to slow simulation, specified as off or on.

Programmatic Use

Parameter: EnablePacing
Value: 'off' | 'on'
Default: 'off'

Approximate ratio of simulation time to wall clock time, specified as a positive scalar number. By default, when you enable simulation pacing, the software slows the simulation to a rate of approximately one second of simulation time per second of clock time.

You can use the value slider or the text box to specify the approximate pacing rate. The ratio of simulation time to clock time is not limited to the range shown in the value slider.

Dependencies

To enable this parameter, select Enable pacing to slow down simulation.

Programmatic Use

Parameter: PacingRate
Type: string | character vector
Value: positive scalar number
Default: '1'

Tips

  • The simulation pacing does not apply when you step through a simulation by clicking Step Forward or Step Backward. When you finish stepping and click Continue, the pacing does apply.

  • Because simulation pacing intentionally slows simulation, profiling a model using the Simulink Profiler is not supported when simulation pacing is enabled. To use the Simulink Profiler, disable simulation pacing.

Version History

Introduced in R2018a