Main Content


Execute particular phase of simulation of model


[sys,x0,str,ts] = model([],[],[],'sizes');
[sys,x0,str,ts] = model([],[],[],'compile');
outputs = model(t,x,u,'outputs');
derivs = model(t,x,u,'derivs');
dstates = model(t,x,u,'update');


The model command executes a specific phase of the simulation of a Simulink® model whose name is model. The command's last argument (flag) specifies the phase of the simulation to be executed. See Simulation Phases in Dynamic Systems for a description of the steps that Simulink software uses to simulate a model.

This command ignores the effects of state transitions and conditional execution. Therefore, it is not suitable for models which have such logic. Use this command for models which can be represented as simple dynamic systems. Such systems should meet these requirements.

  • All states in the model must be built-in non-bus data types. For a discussion on built-in data types, see About Data Types in Simulink.

  • If you are using vector format to specify the state, this command can access only non-complex states of double data type.

  • There is minimal amount of state logic (Stateflow, conditionally executed subsystems etc.)

  • The models are not mixed-domain models. That is, most blocks in the model are built-in Simulink blocks and do not include user-written S-functions or blocks from other Sim* products.

For models which do not comply with these requirements, using this command can cause Simulink to produce results which can only be interpreted by further analyzing and simplifying the model.


The state variable x can be represented in structure as well as vector formats. The variable follows the limitations of the format in which it is specified.

This command is also not intended to be used to run a model step-by-step, for example, to debug a model. Use the Simulink debugger if you need to examine intermediate results to debug a model.



Vector of model size data:

  • sys(1) = number of continuous states

  • sys(2) = number of discrete states

  • sys(3) = number of outputs

  • sys(4) = number of inputs

  • sys(5) = reserved

  • sys(6) = direct-feedthrough flag (1 = yes, 0 = no)

  • sys(7) = number of Continuous, Discrete, Fixed in minor step, and Controllable sample times (= number of rows in ts)


Vector containing the initial conditions of the system's states


Vector of names of the blocks associated with the model's states. The state names and initial conditions appear in the same order in str and x0, respectively.


An m-by-2 matrix containing the sample time (period, offset) information of the Continuous, Discrete, Fixed in minor step, and Controllable sample times in the model.

For more information on the sample times in Simulink, see Types of Sample Time.


Outputs of the model at time step t.


Derivatives of the continuous states of the model at time t.


States of the model at time t returned as either a structure or an array. Simulink returns a structure when the model has states and x is either empty ([]) or in structure format. Otherwise, Simulink returns an array.

  • If the return type is a vector or array, Simulink returns real double discrete states only.

  • If the return type is a structure, Simulink returns a structure that contains both continuous and discrete states of built-in types only. Non-built-in types are omitted.


Time step, specified as real double in scalar format.


State vector, specified as real double in structure or vector format.


Inputs, specified as real double in vector format.


Specification of the simulation phase to be executed:

  • 'sizes' executes the size computation phase of the simulation. This phase determines the sizes of the model's inputs, outputs, state vector, etc.

  • 'compile' executes the compilation phase of the simulation. The compilation phase propagates signal and sample time attributes.

  • 'update' computes the next values of the model's discrete states.

  • 'outputs' computes the outputs of the model's blocks at time t.

  • 'derivs'computes the derivatives of the model's continuous states at time step t.

  • 'term' causes Simulink software to terminate simulation of the model.


The output, update, and derivs flags are valid only for single-tasking models. For more information on single-tasking and multi-tasking, see Tasking Modes (Simulink Coder).


The following command executes the compilation phase of the vdp model that comes with Simulink software.

vdp([], [], [], 'compile')

The following command terminates the simulation initiated in the previous example.

vdp([], [], [], 'term')


Simulink does not let you close a model while it is compiling or simulating. For all phases except the 'sizes' phase, before closing the model, you must invoke the model command with the 'term' argument.

Version History

Introduced in R2007a

See Also