Declare Workspace Variables as Tunable Parameters Using the Model Parameter Configuration Dialog Box - MATLAB & Simulink (original) (raw)
Main Content
You can use the Model Parameter Configuration dialog box to declare numeric MATLABĀ® variables in the base workspace as tunable parameters. You can select code generation options, such as storage class, for each tunable parameter.
However, it is a best practice to instead use parameter objects to declare tunable parameters. Do not use the Model Parameter Configuration dialog box to select parameter objects in the base workspace. To use parameter objects, instead of the Model Parameter Configuration dialog box, to declare tunable parameters, see C Data Code Interface Configuration for Model Interface Elements.
Note
You cannot use the Model Parameter Configuration dialog box to declare tunable parameters for a referenced model. Use Simulink.Parameter
objects instead.
Declare Existing Workspace Variables as Tunable Parameters
Use the Model Parameter Configuration dialog box to declare existing workspace variables as tunable parameters for a model.
- In the Configuration Parameters dialog box, on the > pane, set the Default parameter behavior parameter to
Tunable
and click Configure. - In the Model Parameter Configuration dialog box, under Source list, select a method to populate the list of available workspace variables.
- Select
MATLAB workspace
to view numeric variables that are defined in the base workspace. - Select
Referenced workspace variables
to view only the numeric variables in the base workspace that the model uses. Selecting this option begins a diagram update and a search for used variables, which can take time for a large model.
- Select
- In the Model Parameter Configuration dialog box, underSource list, select one or more workspace variables.
- Click Add to table. The variables appear as tunable parameters under Global (tunable) parameters, and appear in italic font under Source list.
- Optionally, select a parameter under Global (tunable) parameters, and adjust the code generation settings for the parameter. For more information about adjusting the code generation options for tunable parameters, seeSet Tunable Parameter Code Generation Options
- Click OK to apply your selection of tunable parameters and close the dialog box.
Declare New Tunable Parameters
Use the Model Parameter Configuration dialog box to declare new tunable parameters. You can use this technique to declare the names of tunable parameters, and to adjust their code generation settings, before you create the corresponding workspace variables.
- In the Configuration Parameters dialog box, on the pane, set the Default parameter behavior parameter to
Tunable
and click Configure. - In the Model Parameter Configuration dialog box, underGlobal (tunable) parameters, clickNew.
- Under the Name column, specify a name for the new tunable parameter.
- Optionally, adjust the code generation settings for the new parameter. For more information about adjusting the code generation options for tunable parameters, see Set Tunable Parameter Code Generation Options
- Click OK to apply your changes and close the dialog box.
Set Tunable Parameter Code Generation Options
To set the properties of tunable parameters listed under Global (tunable) parameters in the Model Parameter Configuration dialog box, select a parameter and specify a storage class and, optionally, a storage type qualifier.
Property | Description |
---|---|
Storage class | Select one of the following to use for code generation:Model defaultExportedGlobalImportedExternImportedExternPointerFor more information about tunable parameter storage classes, see C Data Code Interface Configuration for Model Interface Elements. |
Storage type qualifier | For variables with a storage class other thanAuto, you can add a qualifier (such as const orvolatile) to the generated storage declaration. To do so, you can select a predefined qualifier from the list, or add qualifiers not in the list by typing them in. The code generator does not check the storage type qualifier for validity, and includes the qualifier text in the generated code without checking syntax. |
Programmatically Declare Workspace Variables as Tunable Parameters
Tune Parameters from the Command Line
When parameters are MATLAB workspace variables, the Model Parameter Configuration dialog box is the recommended way to see or set the properties of tunable parameters. In addition to that dialog box, you can also use MATLABget_param
and set_param
commands.
The following commands return the tunable parameters and corresponding properties:
get_param(gcs,'TunableVars')
get_param(gcs,'TunableVarsStorageClass')
get_param(gcs,'TunableVarsTypeQualifier')
The following commands declare tunable parameters or set corresponding properties:
set_param(gcs,'TunableVars',str)
The argumentstr
(character vector) is a comma-separated list of variable names.set_param(gcs,'TunableVarsStorageClass',str)
The argumentstr
(character vector) is a comma-separated list of storage class settings.
The valid storage class settings areAuto
ExportedGlobal
ImportedExtern
ImportedExternPointer
set_param(gcs,'TunableVarsTypeQualifier',str)
The argumentstr
(character vector) is a comma-separated list of storage type qualifiers.
The following example declares the variable k1
to be tunable, with storage class ExportedGlobal
and type qualifierconst
. The number of variables and number of specified storage class settings must match. If you specify multiple variables and storage class settings, separate them with a comma.
set_param(gcs,'TunableVars','k1') set_param(gcs,'TunableVarsStorageClass','ExportedGlobal') set_param(gcs,'TunableVarsTypeQualifier','const')