Skip to Main Content Skip to Search
Product Documentation

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

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

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

  1. Specify parameter name-value pairs within the sim command:

    simOut = sim('vdp','SimulationMode','rapid','AbsTol','1e-5',...
                'SaveState','on','StateSaveName','xoutNew',...
                'SaveOutput','on','OutputSaveName','youtNew');
  2. Specify parameter values in a structure, paramNameValStruct:

    paramNameValStruct.SimulationMode = 'rapid';
    paramNameValStruct.AbsTol         = '1e-5';
    paramNameValStruct.SaveState      = 'on';
    paramNameValStruct.StateSaveName  = 'xoutNew';
    paramNameValStruct.SaveOutput     = 'on';
    paramNameValStruct.OutputSaveName = 'youtNew';
    simOut = sim('vdp',paramNameValStruct);
  3. Specify a configuration set containing the parameter values:

    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

Backwards Compatible Syntax | parfor | Rapid Accelerator Simulations Using PARFOR | sldebug

  


Related Products & Applications

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.

 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS