| Contents | Index |
S-functions (system-functions) provide a powerful mechanism for extending the capabilities of the Simulink® environment. An S-function is a computer language description of a Simulink block written in MATLAB®, C, C++, or Fortran. C, C++, and Fortran S-functions are compiled as MEX files using the mex utility (see Building MEX-Files in MATLAB External Interfaces). As with other MEX files, S-functions are dynamically linked subroutines that the MATLAB interpreter can automatically load and execute.
S-functions use a special calling syntax called the S-function API that enables you to interact with the Simulink engine. This interaction is very similar to the interaction that takes place between the engine and built-in Simulink blocks.
S-functions follow a general form and can accommodate continuous, discrete, and hybrid systems. By following a set of simple rules, you can implement an algorithm in an S-function and use the S-Function block to add it to a Simulink model. After you write your S-function and place its name in an S-Function block (available in the User-Defined Functions block library), you can customize the user interface using masking (see Creating Custom Blocks).
You can use S-functions with the Simulink Coder™ product. You can also customize the code generated for S-functions by writing a Target Language Compiler (TLC) file. See Insert S-Function Code in the Simulink Coder User's Guide for more information.
![]() | Overview of S-Functions | Using S-Functions in Models | ![]() |

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.
| © 1984-2012- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |