User`s guide
Introduction
2-3
Building S-functions can be thought of as two separate tasks:
• Initializingblockcharacteristics,includingnumber ofinputs,outputs,initial
conditions of continuous and discrete states, and sample times
• Placing your algorithms in the appropriate S-function routine
Defining S-Function Block Characteristics
For S imulink to recognize an M-file S-function, you must provide it with
specific information about t he S -function. This informatio n includes the
number of inputs, outputs, states, and other block characteristics.
To give Simulink this information, call the
simsizes function at the beginning
of
mdlInitializeSizes:
sizes = simsizes;
This function returns an uninitialized sizes structure. You must load the
sizes structure with information about the S-function. The tabl e below li sts
the
sizes structure fields and describes the information contained in each
field.
After you initialize the
sizes structure, call simsizes again:
sys = simsizes(sizes);
This p a ss es the infor m ati on in the sizes structure t o sys,avectorthatholds
the information for use by Simulink.
Table 2-2: Fields in the sizes Structure
Field Name Description
sizes.NumContStates
Number of continuous states
sizes.NumDiscStates
Number of discrete states
sizes.NumOutputs
Number of outputs
sizes.NumInputs
Number of inputs
sizes.DirFeedthrough
Flag for direct feedthrough
sizes.NumSampleTimes
Number of sample times