User`s guide

3 Writing S-Functions As C-MEX files
3-16
Figure 3-1: The Calling Sequence for S-Functions
Initialization
mdlSetInputPortWidth/mdlSetOutputPortWidth
mdlInitializeSizes
mdlInitializeSampleTimes
mdlSetWorkWidths
mdlInitializeConditions
mdlStart
p. 3-28
p. 3-35
p. 3-46
p. 3-48
p. 3-48
p. 3-36
Simulation loop
Called here if your S-function
reside s in an enabl ed subsyst em
configured to reset states, and the
subsyst em has just enabled. It is
also called at the start of simulation .
mdlDerivatives
mdlOutputs
mdlOutputs
mdlDerivatives
mdlZeroCrossings
Integration stages. Only
perf ormed if your
S-function has continuous
states.
Integration (minor time step)
mdlCheckParameters
Calledduringthesimulationloop
when parameters to your
S-function change.
Only called if your S-functi on has a
variabl e step sample time.
Legend:
required
opti onal
Calledwhenparametersarechanged
during a simulation.
mdlGetTimeOfNextVarHit
mdlProcessParameters
mdlOutputs (major time step)
mdlUpdate (major time step)
mdlInitializeConditions
p. 3-26
p. 3-24
p. 3-48
p. 3-50
p. 3-50
p. 3-51
p. 3-51
p. 3-50
p. 3-51
p. 3-53
p. 3-50
p. 3-52
mdlTerminate
mdlSetInputPortSampleTime/mdlSetOutputPortSampleTime
p. 3-33
Zerocro ssi ngfinding.Only
performed if your
S-functionhasnonsampled
zero
crossings.