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 Build MEX File).
As with other MEX files, S-functions are dynamically linked subroutines
that the MATLAB execution engine 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 What Are Masks?).
If you have Simulink Coder™, you can use S-functions with the software. You can also customize the code generated for S-functions by writing a Target Language Compiler (TLC) file. For more information, see S-Functions and Code Generation.