Documentation Center

  • Trial Software
  • Product Updates

sim

Simulate dynamic system

Syntax

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

Description

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

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

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

Input Arguments

model

Name of model to simulate.

ParameterName

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:

ParameterDescription
ConcurrencyResolvingToFileSuffix

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

RapidAcceleratorParameterSets

(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', the software does not perform an up-to-date check. 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.

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 software issues a warning message and continues the simulation.

Value

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

configSetParamValue = get_param(configSet, 'StopTime')

ParameterStruct

A structure containing parameter settings

ConfigSet

A configuration set

Output Arguments

simOut

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

Definitions

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.

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

Examples

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', ...
            'SaveState','on','StateSaveName','xoutNew',...
            'SaveOutput','on','OutputSaveName','youtNew',...
            'SignalLogging','on','SignalLoggingName','logsout')
Simulink.SimulationOutput:
       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)
Simulink.SimulationOutput:
    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';
load_system(mdl)
simMode = get_param(mdl, 'SimulationMode');
set_param(mdl, 'SimulationMode', 'rapid')
cs = getActiveConfigSet(mdl);
mdl_cs = cs.copy;
set_param(mdl_cs,'AbsTol','1e-5',...
         'SaveState','on','StateSaveName','xoutNew',...
         'SaveOutput','on','OutputSaveName','youtNew')
simOut = sim(mdl, mdl_cs);
set_param(mdl, 'SimulationMode', simMode)

See Also

| | | | |

Was this topic helpful?