Simulink Reference    
sim

Simulate a dynamic system

Syntax

Description

The sim command executes a Simulink model, using all simulation parameter dialog settings including Workspace I/O options.

You can supply a null ([ ]) matrix for any right-side argument except the first (the model name). The sim command uses default values for unspecified arguments and arguments specified as null matrices. The default values are the values specified by the model. You can set optional simulation parameters, using the sim command's options argument. Parameters set in this way override parameters specified by the model.

If you do not specify the left side arguments, the command logs the simulation data specified by the Workspace I/O pane of the Simulation parameters dialog box (see The Workspace I/O Pane in the online documentation for Simulink).

If you want to simulate a continuous system, you must specify the solver parameter, using simset. The solver defaults to VariableStepDiscrete for purely discrete models.

Arguments

t
Returns the simulation's time vector.
x
Returns the simulation's state matrix consisting of continuous states followed by discrete states.
y
Returns the simulation's output matrix. Each column contains the output of a root-level Outport block, in port number order. If any Outport block has a vector input, its output takes the appropriate number of columns.
y1,...,yn
Each yi returns the output of the corresponding root-level Outport block for a model that has n such blocks.
model
Name of a block diagram.
timespan
Simulation start and stop time. Specify as one of these:
tFinal to specify the stop time. The start time is 0.
[tStart tFinal] to specify the start and stop times.
[tStart OutputTimes tFinal] to specify the start and stop times and time points to be returned in t. Generally, t will include more time points. OutputTimes is equivalent to choosing Produce additional output on the dialog box. For a single-rate discrete system, the additional output times specified by OutputTimes must be integer multiples of the fundamental time step. For such a system, you must use an expression of the form

  • Ts * [vector of integers]
    
where Ts is the fundamental time step to specify the additional output times. Do not use an expression of the form 0:Ts:N*Ts.

options
Optional simulation parameters specified as a structure created by the simset command (see simset).
ut
Optional external inputs to top-level Inport blocks. ut can be a a MATLAB function (expressed as a string) that specifies the input u = UT(t) at each simulation time step, a table of input values versus time for all input ports, or a comma-separated list of tables, ut1, ut2, ..., each of which corresponds to a specific port. Tabular input for all ports can be in the form of a MATLAB array or a structure. Tabular input for individual ports must be in the form of a structure. See Loading Input from the Base Workspace for a description of the array and structure input formats.

Examples

This command simulates the Van der Pol equations, using the vdp model that comes with Simulink. The command uses all default parameters.

This command simulates the Van der Pol equations, using the parameter values associated with the vdp model, but defines a value for the Refine parameter.

This command simulates the Van der Pol equations for 1,000 seconds, saving the last 100 rows of the return variables. The simulation outputs values for t and y only, but saves the final state vector in a variable called xFinal.

See Also

simset, simget


  model simplot