This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.


Update zero-crossing vector




C, C++


void mdlZeroCrossings(SimStruct *S)



SimStruct representing an S-Function block.


An S-function needs to provide this optional method only if it does zero-crossing detection. Implementing zero-crossing detection typically requires using the zero-crossing and mode work vectors to determine when a zero crossing occurs and how the S-function's outputs should respond to this event. The mdlZeroCrossings method should update the S-function's zero-crossing vector, using ssGetNonsampledZCs.

You can use the optional mdlZeroCrossings routine when your S-function has registered the CONTINUOUS_SAMPLE_TIME and has nonsampled zero crossings (ssGetNumNonsampledZCs(S) > 0). The mdlZeroCrossings routine is used to provide the Simulink® engine with signals that are to be tracked for zero crossings. These are typically

  • Continuous signals entering the S-function

  • Internally generated signals that cross zero when a discontinuity would normally occur in mdlOutputs

Thus, the zero-crossing signals are used to locate the discontinuities and end the current time step at the point of the zero crossing. To provide the engine with zero-crossing signals, mdlZeroCrossings updates the ssGetNonsampleZCs(S) vector.


For an example, see sfun_zc_sat.c. A detailed description of this example can be found in Zero Crossings.

Introduced before R2006a