Writing S-Functions    
ssSetNumModes

Specifies the size of the block's mode vector.

Syntax

Arguments

S
   SimStruct representing an S-Function block.

nModes
   Size of the mode vector for the block represented by S. Valid values are 0, a positive integer, or DYNAMICALLY_SIZED.

Description

Sets the size of the block's mode vector to nModes. 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. Simulink 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

See Also
ssGetNumModes, ssGetModeVector


  ssSetNumIWork ssSetNumNonsampledZCs