Main Content

Manage Simscape Run-Time Parameters

By default, all Simscape™ parameters are compile-time configurable. You can only change the value of compile-time parameters in the plant model on your development computer.

Specify Simscape Run-Time Parameters

Some Simscape block parameters are strictly compile-time configurable parameters. To determine if a particular Simscape parameter is supported for run-time configurability, examine the block property inspector settings for the parameter. If a parameter is run-time configurable, you can see an expander symbol in front of its name in the block property inspector. Expanding it exposes the Configurability setting for this parameter, which is set to Compile-time by default. You can change this to Run-time for the parameters that you want to be run-time configurable. You can change this setting at any time before you generate code from your Simscape model.

The figure shows an enabled run-time configurability setting for the Constant voltage parameter of a DC Voltage Source block. If there is no expander in front of a parameter name, or if the Configurability setting is disabled, then the parameter is strictly compile-time configurable.

When you set a Simscape parameter to be run-time configurable, you can leave it as a numerical value, or you can specify a variable in the workspace as shown in the figure. To use a variable:

  1. Use input tools, such as the command prompt, callbacks, scripts, or MAT-files, to assign a value for the variable in the MATLAB® workspace.

  2. Specify the variable for the parameter in the block property inspector setting.

  3. Use input tools to change the value for the variable as desired.

Either way you specify the parameter, the new value will be incorporated when you restart the simulation. 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 Inline, the generated code 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:

  1. Open the model Configuration Parameters. On the Modeling tab, click Model Settings > Model Settings.

  2. Select Code Generation > Optimization.

  3. Select a value for the Default parameter behavior parameter:

    • Tunable (default) — Simulink® Coder™ generates data structures that allow you to change parameters without recompiling between simulation runs.

    • InlineSimulink Coder treats the numeric values of all the block parameters as constants in the generated C code, rendering them non-modifiable.

Selectively Override the Inline Default Behavior

The first run-time configurable parameter that you specify has the highest computational cost, and the added cost for each additional parameter is lower than the last. 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.

To inline with exceptions:

  1. In the Code Generation > Optimization settings, set the Default parameter behavior to Inline.

  2. Click Configure to open the Model Parameter Configuration window.

  3. Remove individual parameters from inlining as necessary.

Related Topics