S-Function Features

The following tables give overviews of the features supported by different types of S-functions. The first table focuses on handwritten S-functions. The second table compares the features of S-functions automatically generated by the S-Function Builder or Legacy Code Tool.

Features of Hand-Written S-Functions

FeatureLevel-1 MATLAB S-FunctionLevel-2 MATLAB S-FunctionHandwritten C MEX S-Function
Data typesSupports signals with a data type of double.Supports any data type supported by Simulink® software, including fixed-point types.Supports any data type supported by Simulink software, including fixed-point types.
Numeric typesSupports only real signals.Supports real and complex signals.Supports real and complex signals.
Frame supportDoes not support frame-based signals.Supports framed and unframed signals.Supports framed and unframed signals.
Port dimensionsSupports vector inputs and outputs. Does not support multiple input and output ports.Supports scalar, 1-D, and multidimensional input and output signals.Supports scalar, 1-D, and multidimensional input and output signals.
S-function APISupports only mdlInitializeSizes, mdlDerivatives, mdlUpdate, mdlOutputs, mdlGetTimeOfNextVarHit, and mdlTerminate.Supports a larger set of the S-function API. See Level-2 MATLAB S-Function Callback Methods for a list of supported methods.Supports the entire S-function API.
Code generation supportDoes not support code generation.Requires a handwritten TLC file to generate code.Natively supports code generation. Requires a handwritten TLC file to inline the S-function during code generation.
Simulink Accelerator modeRuns interpretively and is, therefore, not accelerated.Provides the option to use a TLC file in Accelerator mode, instead of running interpretively.Provides the option to use a TLC or MEX file in Accelerator mode.
Model referenceCannot be used in a referenced model.Supports Normal and Accelerator mode simulations when used in a referenced model. Requires a TLC file for Accelerator mode.Provides options for sample time inheritance and Normal mode support when used in a referenced model. See Model Referencing Limitations
Simulink.
AliasType
and Simulink.
NumericType
support
Does not support these classes.Supports Simulink.NumericType and Simulink.AliasType classes (see Custom Data Types).Supports all of these classes (see Custom Data Types).
Bus input and output signalsDoes not support bus input or output signals.Does not support bus input or output signals.Supports nonvirtual bus input or output signals.
Tunable and run-time parametersSupports tunable parameters during simulation. Does not support run-time parameters.Supports tunable and run-time parameters.Supports tunable and run-time parameters.
Work vectorsDoes not support work vectors.Supports DWork vectors (see Using DWork Vectors in Level-2 MATLAB S-Functions).Supports all work vector types (see Types of DWork Vectors).

Features of Automatically Generated S-Functions

FeatureS-Function BuilderLegacy Code Tool
Data typesSupports any data type supported by Simulink software, including fixed-point types.Supports all built-in data types. To use a fixed-point data type, you must specify the data type as a Simulink.NumericType. You cannot use a fixed-point type with unspecified scaling.
Numeric typesSupports real and complex signals.Supports complex signals only for built-in data types.
Frame supportSupports framed and unframed signals.Does not support frame-based signals.
Port dimensionsSupports scalar, 1-D, and multidimensional input and output signals.Supports scalar, 1-D, and multidimensional input and output signals.
S-function APISupports creation of custom mdlInitializeSizes, mdlInitializeSampleTimes, mdlDerivatives, mdlUpdate, and mdlOutputs. Also allows for automatic generation of mdlStart and mdlTerminate.Supports mdlInitializeSizes, mdlInitializeSampleTimes, mdlStart, mdlInitializeConditions, mdlOutputs, and mdlTerminate.
Code generation supportNatively supports code generation. Also, automatically generates a TLC file for inlining the S-function during code generation.Natively supports code generation optimized for embedded systems. Also, automatically generates a TLC file that supports expression folding for inlining the S-function during code generation.

Simulink Accelerator™ mode

Uses a TLC file in Accelerator mode, if the file was generated. Otherwise, uses the MEX file.Provides the option to use a TLC or MEX file in Accelerator mode.
Model referenceUses default behaviors when used in a referenced model.Uses default behaviors when used in a referenced model.
Simulink.AliasType and Simulink.NumericTypeDoes not support these classes.Supports Simulink.AliasType and Simulink.NumericType.
Bus input and output signalsSupports bus input and output signals. See sfbuilder_bususagesfbuilder_bususage for an example.Supports bus input and output signals. You must define a Simulink.Bus object in the MATLAB® workspace that is equivalent to the structure of the input or output used in the legacy code. Does not support bus parameters.
Tunable and run-time parametersSupports tunable parameters only during simulation. Supports run-time parameters.Supports tunable and run-time parameters.
Work vectorsDoes not provide access to work vectors.Supports DWork vectors with the usage type SS_DWORK_USED_AS_DWORK. See Types of DWork Vectors for a discussion on the different DWork vector usage types.

Was this topic helpful?