sim
Simulate a Simulink model
Syntax
Description
A Simulink® model represents a dynamic system. Simulating a model lets you understand
the behavior of the system as a function of simulated time. The sim
command uses the specified model and applies the arguments to the model. At the end of
the simulation, the sim
command reverts any arguments that it
applied.
simulates the specified model using existing model configuration parameters, and
returns the result as a simOut
=
sim(model
)Simulink.SimulationOutput
object
(single-output format).
In the Data Import/Export pane of the Configuration Parameters dialog box,Single simulation output is selected by default. If the Single simulation output is not selected, the simulation results are returned as a time vector.
To return simulation results using the backward-compatible format (time vector), see Backward-Compatible Syntax.
simulates the specified model using parameter name-value pairs.simOut
=
sim(model
,Name,Value
)
simulates the model using the inputs specified in the simOut
= sim(simIn
)Simulink.SimulationInput
object
simIn
. The sim
command can be used with
an array of SimulationInput
objects to run multiple simulations
in a series. If simIn
is an array of
Simulink.SimulationInput
objects, output is returned as an
array of Simulink.SimulationOutput
objects.
simulates the specified model using the parameter values specified in the structure
simOut
=
sim(model
,ParameterStruct
)ParameterStruct
.
Examples
Input Arguments
Output Arguments
More About
Tips
Parameters specified using the
sim
command override the values defined in the Model Configuration Parameters dialog box. The software restores the original configuration values at the end of simulation.
In the case of a model with a Model block, the parameter specifications are applied to the top model.
When simulating a model with infinite stop time, to stop the simulation, you must press Ctrl+C. Ctrl+C breaks the simulation, and the simulation results are not saved in the MATLAB workspace.
To specify the time span for a simulation, you must specify the
StartTime
andStopTime
parameters.To log the model time, states, or outputs, use the Data Import/Export pane of the Model Configuration Parameters dialog box.
To log signals, either use a To Workspace block such as the To Workspace block or the Scope block, or use Signal Logging. For more information, see Export Signal Data Using Signal Logging.
To get a list of simulation parameters for the model
vdp
, in the MATLAB Command Window, enter:configSet = getActiveConfigSet('vdp') configSetNames = get_param(configSet, 'ObjectParameters')
This command lists several object parameters, including simulation parameters such as
'StopTime'
,'SaveTime'
,'SaveState'
,'SaveOutput'
, and'SignalLogging'
.