Main Content

Specify and Change a Simscape Run-Time Parameter

Prerequisites

Show Simscape Run-Time Parameter Settings

You use block dialog box parameter settings to specify Simscape™ run-time parameters. However, Simscape block dialog box parameter settings do not show run-time settings unless you set the default behavior to do so using MATLAB® preferences. For an example that shows you how to set the default behavior to show run-time parameter settings for run-time configurable Simscape parameters, 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:

  • Set the default to tunable

  • Set the default 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 PM DC Motor example model contains a DC Voltage block. You parameterize the block by specifying the Constant voltage for the source. The voltage is supported as a Simscape run-time parameter. To specify Constant voltage as a run-time configurable parameter:

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

    ssc_dcmotor

  2. From the model window, access the parameter settings for the DC Voltage block.

  3. To specify Constant voltage as a Simscape run-time parameter, for the run-time setting, select Run-time.

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

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

    vDC = 5;

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, click the Fast restart icon on the Simulink Editor toolbar.

  2. To simulate the model, click the Run button on the Simulink Editor toolbar.

  3. Open the Motor RPM scope block. Autoscale to 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 Motor RPM scope block.

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

Related Topics