Writing S-Functions | ![]() ![]() |
Tunable Parameters
Dialog parameters can be either tunable or nontunable. A tunable parameter is a parameter that a user can change while the simulation is running. Use the macro ssSetSFcnParamTunable
in mdlInitializeSizes
to specify the tunability of each dialog parameter used by the macro.
The mdlCheckParameters
method enables you to validate changes to tunable parameters during a simulation run. Simulink invokes the mdlCheckParameters
method whenever a user changes the values of parameters during the simulation loop. This method should check the S-function's dialog parameters to ensure that the changes are valid.
Note
The S-function's mdlInitializeSizes routine should also invoke the mdlCheckParameters method to ensure that the initial values of the parameters are valid.
|
The optional mdlProcessParameters
callback method allows an S-function to process changes to tunable parameters. Simulink invokes this method only if valid parameter changes have occurred in the previous time step. A typical use of this method is to perform computations that depend only on the values of parameters and hence need to be computed only when parameter values change. The method can cache the results of the parameter computations in work vectors or, preferably, as run-time parameters (see Run-Time Parameters).
Tuning Parameters in External Mode
When a user tunes parameters during simulation, Simulink invokes the S-function's mdlCheckParameters
method to validate the changes and then the S-functions' mdlProcessParameters
method to give the S-function a chance to process the parameters in some way. Simulink also invokes these methods when running in external mode, but it passes the unprocessed changes on to the S-function target. Thus, if it is essential that your S-function process parameter changes, you need to create a Target Language Compiler (TLC) file that inlines the S-function, including its parameter processing code, during the code generation process. For information on inlining S-functions, see the Target Language Compiler Reference Guide.
![]() | Dialog Parameters | Run-Time Parameters | ![]() |