| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → Simulink |
| Contents | Index |
| Learn more about Simulink |
| On this page… |
|---|
This sections explains how to run a simulation interactively. See Running a Simulation Programmatically for information on running a simulation from a program, an S-function, or the MATLAB command line.
To start the execution of a model, from the Simulation menu of the Model Editor, select Start or click the Start button on the model toolbar.

Note A common mistake is to start a simulation while the Simulink block library is the active window. Make sure that your model window is the active window before starting a simulation. |
The model execution begins at the start time that you specify on the Configuration Parameters dialog box. Execution continues until an error occurs, until you pause or terminate the simulation, or until the simulation reaches the stop time as specified on the Configuration Parameters dialog box (see Configuration Parameters Dialog Box).
While the simulation is running, a progress bar at the bottom of the model window shows how far the simulation has progressed. A Stop command replaces the Start command on the Simulation menu. A Pause command appears on the menu and replaces the Start button on the model toolbar.

Your computer beeps to signal the completion of the simulation.
Select the Pause command or button to pause the simulation. Once Simulink completes the execution of the current time step, it suspends the simulation. When you select Pause, the menu item and the button change to Continue. (The button has the same appearance as the Start button). You can resume a suspended simulation at the next time step by choosing Continue.
To terminate execution of the model, select the Stop button or the Stop Simulation menu item. Simulink completes the execution of the current time step and then terminates the simulation. Subsequently selecting the Start menu item or button restarts the simulation at the first time step specified on the Configuration Parameters dialog box.
If the model includes any blocks that write output to a file or to the workspace, or if you select output options on the Configuration Parameters dialog box, the Simulink software writes the data when the simulation is terminated or suspended.
You can use the Stop Simulation block to terminate a simulation when the input to the block is nonzero. To use the Stop Simulation block:
Drag a copy of the Stop Simulation block from the Sinks library and drop it into 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 input signal reaches 10.

If the block input is a vector, any nonzero element causes the simulation to terminate.
You can use an Assertion block to pause the simulation when the input signal to the block is zero. To create a pause block:
Drag a copy of the Assertion block from the Model Verification library and drop it into your model.
Connect the Assertion block to a signal whose value becomes zero at the desired pause time.
Open the Block Parameters dialog box of the Assertion block .
Enter the following commands into the Simulation callback when assertion fails field:
set_param(bdroot,'SimulationCommand','pause'),
disp(sprintf('\nSimulation paused.'))Uncheck the Stop simulation when assertion fails option.
Click OK to apply the changes and close this dialog box.
The following model uses a similiarly configured Assertion block, in conjunction with the Relational Operator block, to pause the simulation when the simulation time reaches 5.

When the simulation pauses, the Assertion block displays the following message at the MATLAB command line.
Simulation paused Warning: Assertion detected in 'assertion_as_pause/ Assertion Used to Pause Simulation' at time 5.000000
You can resume the suspended simulation by choosing Continue from the Simulation menu on the model editor, or by selecting the Continue button in the toolbar.
Note The Assertion block uses the set_param command to pause the simulation. See Running a Simulation Programmatically for more information on using the set_param command to control the execution of a Simulink model. |
![]() | Simulation Basics | Specifying a Simulation Start and Stop Time | ![]() |

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |