| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → Simulink |
| Contents | Index |
| Learn more about Simulink |
The general form of the command syntax for running a simulation is:
SimOut = sim('model', Parameters)where model is the name of the block diagram and Parameters can be a list of parameter name-value pairs, a structure containing parameter settings, or a configuration set. The sim command returns, SimOut, a single Simulink.SimulationOutput object that contains all of the simulation outputs (logged time, states, and signals). This syntax is the "single-output format" of the sim command.
SimOut = sim('model', 'ParameterName1', Value1, 'ParameterName2', Value2...);
SimOut = sim('model', ParameterStruct);
SimOut = sim('model', ConfigSet);
During simulation, the specified parameters override the values in the block diagram configuration set.The original configuration values are restored at the end of simulation. If you wish to simulate the model without overriding any parameters, and you want the simulation results returned in the single-output format, then you must do one of the following:
select Return as single object on the Data Import/Export pane of the Configuration Parameters dialog box
specify the ReturnWorkspaceOutputs parameter value as ‘on' in the sim command:
SimOut = sim('model', 'ReturnWorkspaceOutputs', 'on');To log the model time, states, or outputs, use the Configuration Parameters Data Import/Export dialog box. To log signals, either use a block such as the To Workspace block or the Scope block, or use the Signal and Scope Manager to log results directly.
For complete details of the sim command syntax, see the sim reference page. For information about the configuration parameters, see Configuration Parameters Dialog Box.
Following are examples that demonstrate the application of each of the three formats for specifying parameter values using the single-output format of the sim command.
In the following example, the sim syntax specifies the model name, vdp, followed by consecutive pairs of parameter name and parameter value. For example, the value of the SimulationMode parameter is rapid.
simOut = sim('vdp','SimulationMode','rapid','AbsTol','1e-5',...
'SaveState','on','StateSaveName','xoutNew',...
'SaveOutput','on','OutputSaveName','youtNew');
simOutVars = simOut.who;
yout = simOut.find('youtNew');The following example shows how to specify parameter name-value pairs as a structure to 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);The following example shows how to create a configuration set and use it with the sim syntax.
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)
The block diagram parameter, SimulationMode, is not part of the configuration set, but is associated with the model. Therefore, the set_param command saves and restores the original simulation mode by passing the model rather than the configuration set.
For information on how to run simultaneous simulations by calling sim from within parfor, see Running Parallel Simulations.
![]() | About Programmatic Simulation | Using the set_param Command | ![]() |

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 |