Writing S-Functions Previous page   Next Page

Maintaining Level-1 M-File S-Functions

A Level-1 M-file S-function consists of a MATLAB function of the following form

where f is the name of the S-function. During simulation of a model, Simulink repeatedly invokes f, using the flag argument to indicate the task (or tasks) to be performed for a particular invocation. Each time the S-function performs the task and returns the results in an output vector.

A template implementation of an M-file S-function, sfuntmpl.m, resides in matlabroot/toolbox/simulink/blocks. The template consists of a top-level function and a set of skeleton subfunctions, called S-function callback methods, each of which corresponds to a particular value of flag. The top-level function invokes the subfunction indicated by flag. The subfunctions perform the actual tasks required of the S-function during simulation.


Previous page  Runtime Object S-Function Arguments Next page

© 1994-2005 The MathWorks, Inc.