Simulate dynamic system


simOut = sim('model', 'ParameterName1',Value1,'ParameterName2', Value2...);
simOut = sim('model', ParameterStruct);
simOut = sim('model', ConfigSet);


simOut = sim('model', 'ParameterName1',Value1,'ParameterName2', Value2...); causes Simulink® to simulate the block diagram, model, using parameter name-value pairs ParameterName1, Value1 and ParameterName2, Value2.

simOut = sim('model', ParameterStruct); causes Simulink to simulate the block diagram, model, using the parameter values specified in the structure ParameterStruct.

simOut = sim('model', ConfigSet); causes Simulink to simulate the block diagram, model, using the configuration settings specified in the model configuration set, ConfigSet.

When you do not specify an output argument in the sim command, Simulink stores the simulation output in the variable ans.

Input Arguments


Name of model to simulate.


Name of a simulation parameter. Get a list of simulation parameters for the model vdp by enter the following in the MATLAB® Command Window:

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'.

In addition, the sim command accepts the following parameters:


(Rapid Accelerator mode only) Appends this suffix string to the filename of a model (before the file extension) if:

  • The model contains a To File block

  • You call the sim command from parfor.

Debug 'on' | {'off'} | cmds

Starts the simulation in debug mode (see Debugger Graphical User Interface for more information). The value of this option can be a cell array of commands to be sent to the debugger after it starts.

Default is 'off'.

LoggingFileName | {'out.mat'}

Use when you enable LoggingToFile name-value pair for logging to persistent storage. Specify the destination MAT-file for data logging.

Do not use a file name from one locale in a different locale.

LoggingToFile 'on' | {'off'} |

Store logging data that uses Dataset format to persistent storage (MAT-file). Using a Simulink.SimlationData.DatasetRef object to access signal logging and states logging data loads data into the model workspace incrementally. Accessing data for other kinds of logging loads all of the data at once.

Use this feature when logging large amounts of data that can cause memory issues. For details, see Log Data Using Persistent Storage.


(Rapid Accelerator mode only) Returns structure that contains run-time parameters for running Rapid Accelerator simulations in parfor. See sim in parfor with Rapid Accelerator Mode.

RapidAcceleratorUpToDateCheck {'on'} | 'off'

(Rapid Accelerator mode only) Enables/disables up-to-date check. If you set this value to 'off', Simulink does not perform an up-to-date check. It skips the start/stop callbacks in blocks. If you call the sim command from parfor, set this value to 'off'.

Default is 'on'.

SrcWorkspace {base} | current | parent

Specifies the workspace in which to evaluate MATLAB expressions defined in the model. Setting SrcWorkspace has no effect on a referenced model that executes in Accelerator mode. Setting SrcWorkspace to current within a parfor loop causes a transparency violation. See Transparency Violation for more details.

Default is the base workspace.

TimeOut timeout

Specify the time, in seconds, to allow the simulation to run. If you run your model for a period longer than the value of TimeOut, the software issues a warning and stops the simulation.

Trace 'minstep', 'siminfo', 'compile' {''}Enables simulation tracing facilities (specify one or more as a comma-separated list):
  • 'minstep' specifies that simulation stops when the solution changes so abruptly that the variable-step solvers cannot take a step and satisfy the error tolerances.

  • 'siminfo' provides a short summary of the simulation parameters in effect at the start of simulation.

  • 'compile' displays the compilation phases of a block diagram model.

By default, Simulink issues a warning message and continues the simulation.


Value of the simulation parameter. Get the value of the simulation parameter StopTime by entering:

configSetParamValue = get_param(configSet, 'StopTime')


A structure containing parameter settings


A configuration set

Output Arguments


Simulink.SimulationOutput object containing the simulation outputs—logged time, states, and signals


For all three formats of the sim command, the input(s) are parameter specifications that override those defined on the 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.

For additional details about the sim command, see Run Simulation Using the sim Command.


Simulate the model, vdp, in Rapid Accelerator mode for an absolute tolerance of 1e-5 and save the states in xoutNew and the output in youtNew.

Simulate Model with sim Command Line Options

Specify parameter name value-pairs to the sim command:

simOut = sim('vdp','SimulationMode','rapid','AbsTol','1e-5',...
            'StopTime', '30', ... 
            'ZeroCross','on', ...
            'SaveTime','on','TimeSaveName','tout', ...
       tout: [95x1 double]
    xoutNew: [95x2 double]
    youtNew: [95x2 double]

Simulate Model with sim Command Line Options in Structure

Specify parameter name-value pairs structure paramNameValStruct for the sim command:

paramNameValStruct.SimulationMode = 'rapid';
paramNameValStruct.AbsTol         = '1e-5';
paramNameValStruct.SaveState      = 'on';
paramNameValStruct.StateSaveName  = 'xoutNew';
paramNameValStruct.SaveOutput     = 'on';
paramNameValStruct.OutputSaveName = 'youtNew';
simOut = sim('vdp',paramNameValStruct)
    xoutNew: [65x2 double]
    youtNew: [65x2 double]

Simulate Model with sim Command Line Options in Configuration Set

Specify parameter name-value pairs in configuration set mdl_cs for the sim command:

mdl = 'vdp';
simMode = get_param(mdl, 'SimulationMode');
set_param(mdl, 'SimulationMode', 'rapid')
cs = getActiveConfigSet(mdl);
mdl_cs = cs.copy;
simOut = sim(mdl, mdl_cs);
set_param(mdl, 'SimulationMode', simMode)

Introduced before R2006a

Was this topic helpful?