Specify the size of the block's mode vector
int_T ssSetNumModes(SimStruct *S, int_T nModes)
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.