Writing S-Functions Previous page   Next Page

Updating Run-Time Parameters

Whenever a user changes the values of an S-function's dialog parameters during a simulation run, Simulink invokes the S-function's mdlCheckParameters method to validate the changes. If the changes are valid, Simulink invokes the S-function's mdlProcessParameters method at the beginning of the next time step. This method should update the S-function's run-time parameters to reflect the changes in the dialog parameters.

Updating All Parameters at Once

If there is a one-to-one correspondence between the S-function's tunable dialog parameters and the run-time parameters, the S-function can use the SimStruct function ssUpdateAllTunableParamsAsRunTimeParams to accomplish this task. This function updates each run-time parameter to have the same value as the corresponding dialog parameter.

Updating Parameters Individually

If there is not a one-to-one correspondence between the S-function's dialog and run-time parameters or the run-time parameters are transformed versions of the dialog parameters, the mdlProcessParameters method must update each parameter individually.

If a run-time parameter and its corresponding dialog parameter differ only in value, the method can use ssUpdateRunTimeParamData to update the run-time parameter. This function updates the data field in the parameter's attributes record, ssParamRec, with a new value. If the run-time parameter and the dialog parameter differ only in value and data type, the method can use ssUpdateDlgParamAsRunTimeParam to update the run-time parameter. Otherwise, the mdlProcessParameters method must update the parameter's attributes record itself. To update the attributes record, the method should

  1. Get a pointer to the parameter's attributes record, using ssGetRunTimeParamInfo.
  2. Update the attributes record to reflect the changes in the corresponding dialog parameters.
  3. Register the changes, using ssUpdateRunTimeParamInfo.

Previous page  Run-Time Parameters Tuning Runtime Parameters Next page

© 1994-2005 The MathWorks, Inc.