| Writing S-Functions | ![]() |
Maintaining Level-1 M-File S-Functions
| Note The information provided in this section is intended only for use in maintaining existing M-file S-functions based on Level-1 API. You should use the more capable Level-2 API to develop new M-file S-functions (see Writing Level-2 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.
| Runtime Object | S-Function Arguments | ![]() |
© 1994-2005 The MathWorks, Inc.