ssSetNumModes
Specify the size of the block's mode vector
Syntax
int_T ssSetNumModes(SimStruct *S, int_T nModes)
Arguments
SSimStruct that represents an S-Function block.
nModesSize of the mode vector for the block represented by
S. Valid values are0, a positive integer, orDYNAMICALLY_SIZED.
Returns
The number of modes specified by nModes, or
-1 if DYNAMICALLY_SIZED.
Description
Sets the size of the block's mode vector to nModes. The
elements of the mode vector are initialized to NULL until values
are assigned using ssSetModeVectorValue or via the pointer
obtained fromssGetModeVector.
If nModes is DYNAMICALLY_SIZED, you
can specify the true (positive integer) width in
mdlSetWorkWidths; otherwise, the width used is the width of the
signal passing through the block. Use this macro in
mdlInitializeSizes to specify the number of
int_T elements in the mode vector. The Simulink® engine allocates the mode vector and initializes its elements to 0. If
the default value of 0 is not appropriate, you can set the elements of the array to
other initial values in mdlInitializeConditions. Use
ssGetModeVector to access the mode vector.
The mode vector, combined with zero-crossing detection, allows you to create
blocks that have distinct operating modes, depending on the current values of input
or output signals. For example, consider a block that outputs the absolute value of
its input. Such a block operates in two distinct modes, depending on whether its
input is positive or negative. If the input is positive, the block outputs the input
unchanged. If the input is negative, the block outputs the negative of the input.
You can use zero-crossing detection to detect when the input changes sign and update
the single-element mode vector accordingly (for example, by setting its element to 0
for negative input and 1 for positive input). You can then use the mode vector in
mdlOutputs to determine the mode in which the block is
currently operating.
Languages
C, C++
Examples
See the S-function sfun_zc.c used in sfcndemo_sfun_zc and the S-function sfun_zc_sat.c used in sfcndemo_sfun_zc_sat.
See Also
Version History
Introduced before R2006a