Writing S-Functions Previous page   Next Page

Run-Time Parameters

Simulink allows an S-function to create internal representations of external dialog parameters called run-time parameters. Every run-time parameter corresponds to one or more dialog 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. Simulink 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:

Creating Run-Time Parameters

An S-function can create run-time parameters all at once or one by one.

Creating Run-Time Parameters All at Once

Use the SimStruct function ssRegAllTunableParamsAsRunTimeParams in mdlSetWorkWidths to create run-time parameters corresponding to all tunable parameters. This function requires that you pass it an array of names, one for each run-time parameter. Real-Time Workshop uses this name as the name of the parameter during code generation.

This approach to creating run-time parameters assumes that there is a one-to-one correspondence between an S-function's run-time parameters and its tunable dialog parameters. This might not be the case. For example, an S-function might want to use a computed parameter whose value is a function of several dialog parameters. In such cases, the S-function might need to create the run-time parameters individually.

Creating Run-Time Parameters Individually

    To create run-time parameters individually, the S-function's mdlSetWorkWidths method should

  1. Specify the number of run-time parameters it intends to use, using ssSetNumRunTimeParams.
  2. Use ssRegDlgParamAsRunTimeParam to register a run-time parameter that corresponds to a single, untransformed dialog parameter or ssSetRunTimeParamInfo to set the attributes of a run-time parameter that corresponds to more than one dialog parameter or a transformed dialog parameter.

Previous page  Tunable Parameters Updating Run-Time Parameters Next page

© 1994-2005 The MathWorks, Inc.