Writing S-Functions    

Specifying the Number of Sample Times in mdlInitializeSizes

To specify port-based sample times, use

with:

The inputPortIndex and outputPortIndex range from 0 to the number of input (output) ports minus 1.

When you specify port based sample times, Simulink will call mdlSetInputPortSampleTime and mdlSetOutputPortSampleTime to determine the rates of inherited signals. Once all rates have been determined completed, Simulink will also call mdlInitializeSampleTimes to configure function-call connections. If your S-function does not have any function-call connections this routine should be empty.

Hybrid Block-Based and Port-Based Sample Times

The hybrid method of assigning sample times combines the block-based and port-based methods. You first specify, in mdlInitializeSizes, the total number of rates at which your block operates, including both internal and input and output rates, using ssSetNumSampleTimes. You then set the SS_OPTION_PORT_SAMPLE_TIMES_ASSIGNED, using ssSetOption, to tell the simulation engine that you are going to use the port-based method to specify the rates of the input and output ports individually. Next, as in the block-based method, you specify the period and offset of all of the block's rates, both internal and external, using

Finally, as in the port-based method, you specify the rates for each port, using

Note that each of the assigned port rates must be the same as one of the previously declared block rates.


 Port-Based Sample Times Multirate S-Function Blocks