Manage Simscape Run-Time Parameters

By default, all Simscape™ parameters are compile-time configurable parameters. If you change the value of a compile-time parameter, recompile before simulating the modified model. If you want to change the value without recompiling between iterative simulations or in generated code, you must specify a Simscape dialog box parameter as a run-time configurable parameter.

Show Simscape Run-Time Parameter Settings

You use block dialog box parameter settings to configure Simscape run-time parameters. However, Simscape block dialog box parameter settings do not show run-time parameter settings unless you set the default behavior to do so in MATLAB® preferences. For an example that shows you how to set the default behavior to show run-time settings for supported Simscape parameters, see Show Simscape Run-Time Parameter Settings.

Specify Simscape Run-Time Parameters

Some Simscape block parameters are strictly compile-time configurable parameters. You cannot specify strictly compile-time configurable parameters as run-time configurable parameters. To determine if a particular Simscape parameter is supported for run-time configurability, examine the block dialog box settings for the parameter. If an enabled run-time setting appears next to the parameter on the block dialog box, you can specify the parameter as run-time configurable. To do specify Run-time for the setting. You can change the run-time setting on the dialog box from Compile-time to Run-time at any time before you generate code from your Simscape model.

The figure shows an enabled run-time setting for the Constant voltage parameter of a Simscape block. If there is no run-time setting for a parameter, or if the setting is disabled, then the parameter is strictly compile-time configurable.

Simscape run-time parameters are changeable by variable, not by field. That is, to simulate without recompiling after a parameter change, you cannot simply update the value of the parameter in the dialog box setting where you specify the numeric value. You change the value of the variable that represents the parameter in the workspace or in the generated code. To do so, you first:

  1. Specify the parameter as a variable in the dialog box setting.

  2. Save the numeric value for the variable to the MATLAB workspace.

For an example that shows how to specify a Simscape run-time parameter using a variable, see Specify and Change a Simscape Run-Time Parameter.

Set the Default Parameter Behavior for Generated Code

By default, you can change the value of a Simscape run-time parameter while the simulation is stopped without having to recompile the model. If you change the default parameter behavior for code generation to inlined, the generated code algorithm inlines the numeric values of all the block parameters as constants. The code that you generate using inlined parameters is more computationally efficient because it does not have to store or retrieve parameter values.

To set the default behavior for Simscape run-time parameters, on the Model Configuration Parameters > Optimization > Signal and Parameters dialog box, select the Default parameter behavior. Options are:

  • Inline — The Simulink® Coder™ algorithm hard-codes the numeric values of all the block parameters as constants in the generated C code, rendering them non-modifiable.

  • TunableSimulink Coder generates data structures that you can modify to change parameters without recompiling between simulation runs.

Selectively Override the Inline Default Behavior

While computational cost increases if you specify Simscape parameters in your model as run-time configurable, the cost increase is not proportional to the number of parameters that you so specify. If you declare a single parameter as run-time configurable, the computational cost increases sharply. The cost increases less per parameter for any additional Simscape run-time parameters that you specify. Therefore, even if the computational cost for your model decreases greatly with inlining, it decreases only slightly for each Simscape run-time parameter that you selectively inline. However if your model is at risk of overrunning and it contains Simscape run-time parameters, you might decrease the computational cost enough to prevent overruns by selectively excluding only a few Simscape run-time parameters from inlining.

To inline with exceptions, set the Default parameter behavior to Inline and use the Model Parameter Configuration dialog box to remove individual parameters from inlining.

Related Topics