Main Content

Specify and Change a Simscape Run-Time Parameter

You must change the Simscape™ default to show configurability options before the first time you set a parameter to be run-time configurable. If you want to generate code, you may need to change the default inlining behavior. The example demonstrates how you can specify and change a Simscape run-time parameter once you have completed these steps.

Prerequisites

Show Simscape Run-Time Parameter Settings

Simscape block parameters only show configurability settings when you set the default behavior to do so using MATLAB® preferences. For more information, see Show Simscape Run-Time Parameter Settings.

Set the Default Parameter Behavior for Code Generation

Simscape run-time parameters depend on the default parameter behavior setting for code generation. To enable run-time configurability for a Simscape run-time parameter so that you can change its value without recompiling your model, you can:

  • Leave the default as Tunable.

  • Set the default to Inline, and override the default behavior for the parameter with the value that you want to change.

For information on setting and overriding the default behavior for Simscape run-time parameters, see Manage Simscape Run-Time Parameters.

Specify a Parameter as Run-Time Configurable

The Permanent Magnet DC Motor example model contains a DC Voltage block. You parameterize the block by specifying the Constant voltage. The voltage is a Simscape run-time configurable parameter. To specify Constant voltage as a run-time configurable parameter:

  1. To open model, at the MATLAB command prompt, enter:

    ssc_dcmotor

  2. Assign a numeric the value to the variable in the MATLAB workspace:

    vDC = 5;

  3. Double-click the DC Voltage block to edit the parameters.

  4. In the drop-down box to the right of Constant voltage, select Run-time.

  5. Specify the Constant voltage parameter value as the variable vDC.

Change a Simscape Run-Time Parameter Using Fast Restart

To see how altering the value of a run-time configurable parameter can affect simulation results, change the value of the Constant voltage parameter between iterative fast-start simulations.

  1. To enable fast restart, in the Simulationtab, in the Simulate section, click the Fast restart icon .

  2. To simulate the model, click Run.

  3. Open the Scope block called Motor RPM. Select Tools > Axes Scaling > Automatically Scale Axesto see the results better.

  4. Assign a different value to the variable that represents voltage:

    vDC = 1.5;

  5. Simulate the model.

  6. Open the Scope block.

    The results reflect the change in value for the run-time parameter.

Related Topics