Writing S-Functions    

Defining S-Function Block Characteristics

For Simulink to recognize an M-file S-function, you must provide it with specific information about the S-function. This information 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.

This function returns an uninitialized sizes structure. You must load the sizes structure with information about the S-function. The table below lists the fields of the sizes structure and describes the information contained in each field.

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

After you initialize the sizes structure, call simsizes again:

This passes the information in the sizes structure to sys, a vector that holds the information for use by Simulink.


  S-Function Outputs Processing S-Function Parameters