User`s guide
Examples of C MEX-File S-Function Blocks
3-65
Example - Hybrid System S-Functions
The S-function, matlabroot/simulink/src/mixedm.c,isanexampleofa
hybrid (a combination of continuous and discrete states) system.
mixedm.c
combines elements of csfunc.c and dsfunc.c. If you have a hybrid system,
place your continuous equationsin
mdlDerivative andyourdiscreteequations
in
mdlUpdate. In addition, you need to check for sample hits to determine at
what point your S-function is being called.
In Simulink block diagram form, the S-function,
mixedm.c looks like
which implements a continuous integrator followed by a discrete unit delay.
Since there are no tasks to completeat termination,
mdlTerminate is an empty
function.
mdlDerivatives calculatesthe derivativesofthe continuousstatesof
the state vector
x,andmdlUpdate contains the equations used to update the
discrete state vector,
x.