Main Content

Create and Update S-Function Run-Time Parameters

You can create internal representations of external S-function dialog box parameters called run-time parameters. Every run-time parameter corresponds to one or more dialog box parameters and can have the same value and data type as its corresponding external parameters or a different value or data type. If a run-time parameter differs in value or data type from its external counterpart, the dialog parameter is said to have been transformed to create the run-time parameter. The value of a run-time parameter that corresponds to multiple dialog parameters is typically a function of the values of the dialog parameters. The Simulink® engine allocates and frees storage for run-time parameters and provides functions for updating and accessing them, thus eliminating the need for S-functions to perform these tasks. Run-time parameters facilitate the following kinds of S-function operations:

  • Computed parameters

    Often the output of a block is a function of the values of several dialog parameters. For example, suppose a block has two parameters, the volume and density of some object, and the output of the block is a function of the input signal and the mass of the object. In this case, the mass can be viewed as a third internal parameter computed from the two external parameters, volume and density. An S-function can create a run-time parameter corresponding to the computed weight, thereby eliminating the need to provide special case handling for weight in the output computation. See Creating Run-Time Parameters from Multiple S-Function Parameters for more information.

  • Data type conversions

    Often a block needs to change the data type of a dialog parameter to facilitate internal processing. For example, suppose that the output of the block is a function of the input and a dialog parameter and the input and dialog parameter are of different data types. In this case, the S-function can create a run-time parameter that has the same value as the dialog parameter but has the data type of the input signal, and use the run-time parameter in the computation of the output.

  • Code generation

    During code generation, the Simulink Coder™ product writes all run-time parameters automatically to the model.rtw file, eliminating the need for the S-function to perform this task via an mdlRTW method.

Create Run-Time Parameters

In a Level-2 MATLAB® S-function, you create run-time parameters associated with all the tunable dialog parameters. Use the run-time object's AutoRegRuntimePrms method in the PostPropagationSetup callback method to register the block's run-time parameters. For example:

block.AutoRegRuntimePrms;

Update Run-Time Parameters

In a Level-2 MATLAB S-function, update the run-time parameters using the AutoUpdateRuntimePrms method in the ProcessParameters callback method. For example:

block.AutoUpdateRuntimePrms;

See Also

| | |

Related Topics