This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

Simulate a Model Interactively

Simulation Basics

You can simulate a model in the Simulink® Editor using Simulation > Run or the Run button on the toolbar. The Run button also appears in tools within the Simulink Editor. You can simulate from any tool that includes the button, such as the Scope viewer.

Before you start a simulation, you can specify options like simulation start time, stop time, and the solver for solving the model. (See About Solvers) You specify these options in the Configuration Parameters dialog box, which you can open from the Simulation menu or using the Model Configuration Parameters button on the toolbar. These settings are saved with the model in a configuration set. You can create multiple configuration sets for each model and switch between them to see the effects of different settings. See Configuration Reuse.

After you set your model configuration parameters, you can start the simulation. You can pause, resume, and stop simulation using toolbar controls. You can also simulate more than one model at a time, so you can start another simulation while one is running.

During simulation, you cannot make changes to the structure of the model, such as adding or deleting lines or blocks. However, you can make these changes while a simulation is running:

  • Modify some configuration parameters, including the stop time and the maximum step size.

  • Modify the parameters of a block, as long as you do not cause a change in:

    • Number of states, inputs, or outputs

    • Sample time

    • Number of zero crossings

    • Vector length of any block parameters

    • Length of the internal block work vectors

    • Dimension of any signals

You can also examine the model visually as it simulates. For example, you can click a line to see the signal carried on that line on a Floating Scope or Display block. You can also display port values as a model simulates. See Display Port Values for Debugging.

Run, Pause, and Stop a Simulation

To start simulating your model, click the Run button . You can pause, resume, or stop a simulation using the corresponding controls on the toolbar.

The model starts simulating at the specified start time and runs until the specified end time. While the simulation is running, information at the bottom of the editor shows the percentage of simulation completed and the current simulation time.

  • If an error occurs, simulation stops and a message appears. If a warning condition occurs, simulation completes. In both cases, click the diagnostics link at the bottom of the editor to see the message, which helps you to locate errors.

  • Pausing takes effect after the current time step finishes executing. Resuming a paused simulation occurs at the next time step.

  • If you stop a simulation, the current time step completes, and then simulation stops.

  • If the model outputs to a file or to the workspace, stopping or pausing simulation writes the data.

Use Blocks to Stop or Pause a Simulation

Stop Simulation Using Stop Simulation Blocks

You can use the Stop Simulation block to stop a simulation when the input to the block is nonzero. If the block input is a vector, any nonzero element stops the simulation.

  1. Add a Stop Simulation block to your model.

  2. Connect the Stop Simulation block to a signal whose value becomes nonzero at the specified stop time.

For example, this model stops the simulation when the simulation time reaches 10.

Pause Simulation Using Assertion Blocks

You can use an Assertion block to pause the simulation when the input signal to the block is zero. The Assertion block uses the set_param command to pause the simulation. See Control Simulations Programmatically for more information on using the set_param command to control the execution of a Simulink model.

  1. Add an Assertion block to your model.

  2. Connect the Assertion block to a signal whose value becomes zero at the desired pause time.

  3. In the Assertion block dialog box, clear the Stop simulation when assertion fails check box. Enter this command as the value of Simulation callback when assertion fails:

    disp(sprintf('\nSimulation paused.'))

This model uses an Assertion block with these settings to pause the simulation when the simulation time reaches 5.

When the simulation pauses, a message appears that shows the time the block paused the simulation.

You can resume the simulation using Continue as you can for any paused simulation.

See Also

| |

Related Examples

More About

Was this topic helpful?