User`s guide
1 Overview of S-Functions
1-2
Introduction
S-functions (system-functions) provide a powerful mechanism for extending
thecapabilitiesofSimulink
®
.Theintroductorysectionsofthischapterdescribe
what an S-function is and when and why you might use one. This chapter then
presents a comprehensive description of how to write your own S-functions.
S-functions allow you to add your own algorithms to Simulink models. You can
write your algorithms in MATLAB
®
orC. Byfollowingasetofsimplerules,you
can implement your algorithms in an S-function. After you have written your
S-function and placed its name in an S-Function block (available in the
Nonlinear Block sublibrary), you can customize the user interface by using
masking.
You can also customize the code generated by the Real Time Workshop
®
for
S-functions by writing a Target Language Compiler
TM
(TLC) file. See the
Target Language Compiler Reference Guide and the Real-Time Workshop
User’s Guide for more information.
What Is an S-Function?
An S-function is a computer language description of a dynamic system.
S-functions can be written using MATLAB or C. C language S-functions are
compiled as MEX-files u sing the
mex utility described in t he Application
ProgramInterfaceGuide.Aswi th other MEX-files,theyaredynamicallylinked
into MATLAB when needed.
S-functions us e a special calling syntax t hat e nables you to inte r act with
Simulink’s equation solvers. This interact io n is ve ry simila r to the inte raction
that takes p lace bet we e n the solve rs a n d built-in Simul ink blocks.
The form of an S-function is very general and can accommodate continuous,
discrete, and hybrid systems. As a result, nearly all Simuli nk models can be
described as S-functions.
S-functions are incorporated into Simulink models by using t he S-Function
block in the Nonlinea r Block sublibrary. Use the S-Function block ’s d ialog box
to specify the name of t he unde rly ing S-function, as illustra te d in the figure
below: