You can simulate a model in the Simulink® Editor using the Run button on the toolstrip. 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 Solver Selection Criteria) You specify these options in the Configuration Parameters dialog box, which you can open by clicking Model Settings on the Modeling tab. 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 Model Configuration Sets.
By default, simulations start at 0.0 s and end at 10.0 s.
In the Simulink software, time and all related parameters (such as sample times) are implicitly in seconds. If you choose to use a different time unit, scale parameters accordingly.
The Solver configuration pane allows you to specify other start and stop times for the currently selected simulation configuration. See Solver Pane for more information.
Simulation time and actual clock time are not the same. For example, if running a simulation for 10 s usually does not take 10 s as measured on a clock. The amount of time it actually takes to run a simulation depends on many factors including the complexity of the model, the step sizes, and the computer speed.
After you set your model configuration parameters, you can start the simulation. You can pause, resume, and stop simulation using toolstrip 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 toolstrip.
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
set_param command to pause the simulation. See Run Simulations Programmatically
for more information on using the
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.