Main Content

S-Function

Include S-function in model

  • S-Function block

Libraries:
Simulink / User-Defined Functions

Description

The S-Function block provides access to S-functions from a block diagram. The S-function named as the S-function name parameter can be a Level-1 or Level-2 C MEX S-function (see MATLAB S-Function Basics for information on how to create S-functions).

Note

Use the Level-2 MATLAB S-Function block to include a Level-2 MATLAB® S-function in a block diagram.

The S-Function block displays the name of the specified S-function and the number of input and output ports specified by the S-function. Signals connected to the inputs must have the dimensions specified by the S-function for the inputs.

Ports

Input

expand all

You can configure input port using the mdlInitializeSizes callback function. Use the mdlInitializeSizes function to specify number of input ports, dimension of input signals, sample time of each port, and if ports are direct feedthrough.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | fixed point

Output

expand all

You can configure output port using the mdlInitializeSizes callback function. Use the mdlInitializeSizes function to specify number of output ports, dimension of output signals, and sample time of each port.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | Boolean | fixed point | enumerated | bus

Parameters

expand all

Use this parameter to specify the name of your S-function.

Programmatic Use

Block Parameter: FunctionName
Type: character vector
Value: name of the S-function
Default: 'system'

Specify the additional S-function parameters.

The function parameters can be specified as MATLAB expressions or as variables separated by commas. For example,

A, B, C, D, [eye(2,2);zeros(2,2)]

Note that although individual parameters can be enclosed in brackets, the list of parameters must not be enclosed in brackets.

Programmatic Use

Block Parameter: Parameters
Type: character vector
Value: S-function parameters
Default: ' '

This parameter applies only if this block represents a C MEX S-function and you intend to use the Simulink® Coder™ software to generate code from the model containing the block. If you use it, when you are ready to generate code, you must force the coder to rebuild the top model as explained in Control Regeneration of Top Model Code (Simulink Coder).

For more information on using this parameter, see Specify Additional Source Files for an S-Function (Simulink Coder).

Programmatic Use

Block Parameter: SFunctionModules
Type: character vector
Value: character vector of file names
Default: ' '

Block Characteristics

Data Types

Booleana | busa | doublea | fixed pointba | halfa | integera | singlea | stringa

Direct Feedthrough

yesa

Multidimensional Signals

yesa

Variable-Size Signals

yesa

Zero-Crossing Detection

yesa

a Actual data type or capability support depends on block implementation.

b See Writing Fixed-Point S-Functions for details on using fixed-point data types in S-functions.

Extended Capabilities

Version History

Introduced before R2006a