User`s guide
1 Overview of S-Functions
1-10
width can also be used to determine the number of continuous states, the
number of discrete states, and the number of outputs.
Within an M-file S-function, to indicate that the input width is dynamically
sized, specify a value of -1 for the appropriate fields in the
sizes structure,
which is returned during the
mdlInitializeSizes call. You can determine the
actual input width when your S-function is called by using
length(u).Ifyou
specify a width of 0, then the input port will be removed from the S-function
block. Handling of port widths is similar for C MEX S-function. C MEX
S-functions also let you have multiple input/output ports.
For example, the illustration below shows two instances of the same
S-Function block in a model.
The upper S-Function block is driven by a block with a three-element output
vector. The lower S-Function block is driven by a block with a scalar output. By
specifying that the S-Function block has dynamically sized inputs, t he same
S-function can accommodate both situations. Simulink automatically calls the
block with the appropriately sized input vector. Similarly, if other block
characteristics, such as the number of outputs or the number of discrete or
continuous states, are specified as dynamically sized, Simulink defines these
vectors to be the same length as the input vector.
C MEX S-functions give you more flexibility in specifying the widths of input
and output ports. See “Creating More Complex C MEX S-Functions” on page
3–10.
Setting Sample Times and Offsets
Both M-file and C MEX S-functions allow a high degree of flexibility in
specifying when an S-function executes. Simulink provides the following
options for sample times: