Writing S-Functions | ![]() ![]() |
Passing Parameters to S-Functions
The S-function block's S-function parameters field allows you to specify parameter values to be passed to the corresponding S-function. To use this field, you must know the parameters the S-function requires and the order in which the function requires them. (If you do not know, consult the S-function's author, documentation, or source code.) Enter the parameters, separated by a comma, in the order required by the S-function. The parameter values can be constants, names of variables defined in the model's workspace, or MATLAB expressions.
The following example illustrates usage of the S-function parameters field to enter user-defined parameters.
The model in this example incorporates limintm
, a sample S-function that comes with Simulink. The function's source code resides in toolbox/simulink/blocks
. The limintm
function accepts three parameters: a lower bound, an upper bound, and an initial condition. It outputs the time integral of the input signal if the time integral is between the lower and upper bounds, the lower bound if the time integral is less than the lower bound, and the upper bound if the time integral is greater than the upper bound. The dialog box in the example specifies a lower and upper bound and an initial condition of 2, 3, and 2.5, respectively. The scope shows the resulting output when the input is a sine wave of amplitude 1.
See Processing S-Function Parameters and Handling Errors for information on how to access user-specified parameters in an S-function.
You can use Simulink's masking facility to create custom dialog boxes and icons for your S-function blocks. Masked dialog boxes can make it easier to specify additional parameters for S-functions. For discussions of additional parameters and masking, see Using Simulink.
![]() | Using S-Functions in Models | When to Use an S-Function | ![]() |