You can create custom blocks whose properties and behaviors are defined by MATLAB® functions called MATLAB S-functions. The Level-2 MATLAB S-function application programming interface (API) allows you to create blocks that have many of the features and capabilities of Simulink® built-in blocks, including:
Multiple input and output ports
1-D, 2-D, and n-D input and output signals
All data types supported by the Simulink software
Real or complex signals
Multiple sample rates
User-defined data and work vectors
Tunable and run-time parameters
Note: Level-2 MATLAB S-functions do not support zero-crossing detection.
For information on how to write a Level-2 MATLAB S-functions, see Write Level-2 MATLAB S-Functions.
If you have Simulink Coder™, you can generate code for Level-2 MATLAB S-functions if they are inlined. For more information, see Inlining S-Functions (Simulink Coder).
Note: This version of the Simulink software also supports a predecessor API known as the Level-1 MATLAB S-function. This ensures that you can simulate models developed with earlier releases that use Level-1 MATLAB S-functions in their S-Function blocks (see Maintain Level-1 MATLAB S-Functions). Level-1 MATLAB S-functions support a much smaller subset of the S-function API then Level-2 MATLAB S-functions, and their features are limited compared to built-in blocks. Use the Level-2 API, not the Level-1 API, to develop new MATLAB S-functions.