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 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.
Number of states, inputs, or outputs
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.
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.
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.
Add a Stop Simulation block to your model.
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.
You can use an Assertion block
to pause the simulation when the input signal to the block is zero.
The Assertion block uses the
to pause the simulation. See Control Simulation Using the set_param Command for more information on
set_param command to control the execution
of a Simulink model.
Add an Assertion block to your model.
Connect the Assertion block to a signal whose value becomes zero at the desired pause time.
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:
set_param(bdroot,'SimulationCommand','pause'), 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.