| Simulink Reference | ![]() |
Syntax
Description
The sim command executes a Simulink model, using all Configuration Parameters dialog box settings, including the options specified on the Data Import/Export pane.
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 Data Import/Export pane of the Configuration Parameters dialog box (see Data Import/Export 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.
Note
The base workspace for a simulation launched by the sim command is the MATLAB workspace by default, with one exception. The exception is that the default workspace for To Workspace blocks is the current workspace, i.e., the workspace of the function that invoked the sim command. You can use the DstWorkspace and SrcWorkspace options of the sim command (see simset) to change these defaults. For example, suppose that you want to use the workspace of the function that invokes the sim command as the base workspace of the simulation. To do this, specify current as the value of the DstWorkspace and SrcWorkspace options.
|
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 formwhere 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 Importing Input from the MATLAB Workspace in the online documentation 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.
[t,x,y] = sim('vdp', 1000, simset('MaxRows', 100, 'OutputVariables', 'ty', 'FinalStateName', 'xFinal'));
See Also
| model | simplot | ![]() |
© 1994-2005 The MathWorks, Inc.