Writing S-Functions    

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:

S-functions can be either single or multirate; a multirate S-function has multiple sample times.

Sample times are specified in pairs in this format: [sample_time, offset_time]. The valid sample time pairs are

where

and the italics indicate that a real value is required.

Alternatively, you can specify that the sample time is inherited from the driving block. In this case the S-function can have only one sample time pair

or

where

The following guidelines might help you specify sample times:

If your S-function has no intrinsic sample time, you must indicate that your sample time is inherited. There are two cases:


  S-Function Concepts S-Function Examples