Writing S-Functions | ![]() ![]() |
Work Vectors and Zero Crossings
The mode-work vector and the nonsampled zero-crossing vector are typically used with zero crossings. Elements of the mode vector are integer values. You specify the number of mode-vector elements in mdlInitializeSizes,
using ssSetNumModes(S,num)
. You can then access the mode vector using ssGetModeVector
. The mode vector is used to determine how the mdlOutputs
routine should operate when the solvers are homing in on zero crossings. The zero crossings or state events (i.e., discontinuities in the first derivatives) of some signal, usually a function of an input to your S-function, are tracked by the solver by looking at the nonsampled zero crossings. To register nonsampled zero crossings, set the number of nonsampled zero crossings in mdlInitializeSizes,
using ssSetNumNonsampledZCs(S, num)
. Then define the mdlZeroCrossings
routine to return the nonsampled zero crossings. See matlabroot
/simulink/src/sfun_zc.c
for an example.
![]() | Work Vectors | Example Involving a Pointer Work Vector | ![]() |