Writing S-Functions    

Example of a Discrete State S-Function

The matlabroot/simulink/src/dsfunc.c example shows how to model a discrete system in a C MEX S-function. Discrete systems can be modeled by the following set of equations.

dsfunc.c implements a discrete state-space equation. The output portion is placed in mdlOutputs and the update portion in mdlUpdate. To visualize how the simulation works, refer to the flowchart in How Simulink Interacts with C S-Functions. The output equation above corresponds to the mdlOutputs in the major time step. The preceding update equation corresponds to the mdlUpdate in the major time step. If your model does not contain continuous elements, the integration phase is skipped and time is moved forward to the next discrete sample hit.

matlabroot/simulink/src/dsfunc.c


  Example of a Continuous State S-Function Example of a Hybrid System S-Function