User`s guide

2 Writing S-Functions As M-Files
2-14
Example - Hybrid System S-Functions
Simulink includes a function called mixedm.m, which is an example of a hybrid
system (a combination of continuous and discrete states) modeled in an
S-function. Handling hybrid systems is fairly straightforward; the
flag
parameter forces the calls to the correct S-function subroutine for the
continuousand discrete parts ofthe system. One subtlety of hybrid S-functions
(or any multirate S-function) is that Simulink calls the
mdlUpdate, mdlOutput,
and
mdlGetTimeOfNextVarHit routines at all sample times. Thismeansthatin
these routines you must test to determine which sample hit is being processed
and only perform updates that correspond to that sample hit.
mixed.m models a continuous Integrator followed by a discrete Unit Delay. In
Simulink block diagram form, the model looks like this: