Main Content

Specify and Change a Simscape Run-Time Parameter

If you want to generate code, you may need to change the default inlining behavior. This example shows how you can specify and change a Simscape™ run-time parameter once you have completed this step.

Prerequisites

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 the model, at the MATLAB® command prompt, enter:

    openExample('simscape/PermanentMagnetDCMotorExample')

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

    vDC = 5;

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

  4. In the Configurability drop-down box for 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, navigate to the Simulate section under the Simulation tab and 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 Axes Limitsto 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