Main Content

Edit Block Parameters

Parameters specify how a block behaves in the model.

You can use the default parameter values or set your own values using the block icon, the Block Parameters dialog box, or the Property Inspector. You can also set parameters programmatically and specify block parameters as variables.

Edit Parameters on Block Icon

For blocks that display a parameter value on the block icon, you can edit the value directly on the icon:

  1. Select the block.

  2. Click on the parameter value on the block icon.

  3. Enter a new value.

  4. Press Enter.

    Note

    The block icon only displays the new value if the value fits on the icon.

    On the left, a gain value of 1000 being entered on the icon of a Gain block, and on the right, the Gain block icon shows the text -K-

You can also edit enumerated block parameter values on the block icon:

  • For the block parameters that have a fixed set of values, you can select the value from a list on the block icon using the cursor or arrow keys.

    These blocks have this feature:

    For example, for the Rounding Function block, you can select the Function parameter from a list of values:

    1. Select the Rounding Function block.

    2. Point to the block icon. The editable parameter value appears underlined.

    3. Click the underlined text to edit the value. A list with Function parameter values appears.

    4. Select a new value from the list using the cursor or the arrow keys.

  • The Goto and From blocks are a special case. While they pair with each other as related blocks, for the Goto block, you can only type a new Goto tag parameter value on the block icon. For the From block, you can only select the Goto tag parameter value from a list on the block icon.

    Note

    Typing a new value for the Goto block removes unmatched values from the list.

    For example, consider a From block with the Goto Tag parameter value sensor_A and three Goto blocks with the Goto Tag parameter values sensor_A, sensor_B, and sensor_C.

    There are three Sine Wave blocks, each connected to a Goto block. To the right of these blocks, a From block connects to a Gain block with a value of 5, which connects to a Scope block. The Goto block with the Goto tag value sensor_A is selected, and the From block is highlighted in purple.

    To change the Goto Tag parameter value of the highlighted Goto and From block pair to a new value:

    1. Select a Goto block, then click on the text on the block icon.

    2. Type in a new name for the tag.

      Sine Wave block connected to a Goto block, and on the Goto block icon, the Goto tag parameter value new is displayed

    3. Press Enter.

    4. Select the From block.

    5. Click the text on the block icon. A list with Goto tag parameter values appears.

      A From block connects to a Gain block, which connects to a Scope block. A list with Goto tag parameter values expands from the From block icon. The values in the list are new, sensor_B, and sensor_C.

    6. Select the new tag name that you assigned to the Goto block.

    Alternatively, to connect the From block to one of the other two Goto blocks, expand the list on the From block icon and select the tag of the Goto block to which you want to connect.

Edit Parameters Using the Property Inspector

To edit parameters that you cannot edit on the block icon, use the Property Inspector.

To edit a parameter using the Property Inspector:

  1. Select the block.

  2. Check if the Property Inspector is open.

    If the Property Inspector window is not visible, check whether the right edge of the Simulink® window displays a Property Inspector tab.

    • If a tab is displayed, the Property Inspector is open and minimized. To expand the Property Inspector window, click the tab.

    • If no tab is displayed, the Property Inspector is closed. To open the Property Inspector, in the Simulink Toolstrip, on the Modeling tab, in the Design section, select Property Inspector.

  3. In the Property Inspector, click the Parameters tab.

  4. On the Parameters tab, find the name of the parameter whose value you want to edit.

  5. Edit the parameter value in the corresponding text box.

Tip

To hide the Property Inspector, click the canvas. If the Property Inspector does not hide when you click the canvas, in the upper right-corner of the Property Inspector window, click the down arrow and select Minimize.

To show the Property Inspector again, click the Property Inspector tab.

The Property Inspector for a Ramp block is open to the Parameters tab. The Slope is set to 2 and the Start time is set to 3. The Property Inspector tab at the right edge of the Simulink window is labeled with the text "Click to Expand Property Inspector Window".

Edit Parameters Using the Block Parameters Dialog Box

To edit parameters that you cannot edit on the block icon, you can also use the Block Parameters dialog box.

To edit a parameter using the Block Parameters dialog box:

  1. Double-click the block. The Block Parameters dialog box appears.

  2. In the Block Parameters dialog box, find the name of the parameter whose value you want to edit.

  3. Edit the parameter value in the corresponding text box. When you edit a parameter value, the text box turns yellow.

  4. Click OK.

Block Parameters dialog box for Ramp block with the Slope set to 2, the Start time set to 3, and the Slope and Start time text boxes are yellow

Edit Parameters Programmatically

To edit the value of a parameter programmatically, use the set_param function.

To obtain the value of a parameter programmatically, use the get_param function.

Specify Block Parameters as Variables

If you want to be able to edit the value of a parameter from the MATLAB® Command Window, a script, or the Workspace Browser, specify the value of the parameter as a variable or as an expression that contains variables. When you change the value of the variable, the value of the parameter also changes.

You can also use the set_param function to edit the value from the command window or a script. However, specifying the parameter as a variable makes your code more compact. You also do not need to update your code when model or block names change.

To specify the value of a parameter as a variable:

  1. Initialize the variable in the MATLAB workspace (base, model, or mask) in which the parameter value is specified.

  2. Change the parameter value to the name of the variable or to the variable expression.

Tip

When you set a block parameter value to a variable or function in the Block Parameters dialog box or the Property Inspector, Simulink provides a list based on the text you type. Instead of completely typing a variable name, you can type part of it and then select the full name from the list.

The list includes:

  • Variables and objects from every workspace (base, model, and mask)

  • Data dictionary

  • Referenced dictionary visible to the block parameter

Autocomplete is available for variables, fields of structures and objects, and for functions on the MATLAB path.

When you specify the value of a parameter as a variable or variable expression, the Block Parameters dialog box and the Property Inspector display the value of the variable or the expression.

The text box where you enter the parameter value displays the variable or expression on the left and the value on the right.

The value of the variable called x is 40. In the Block Parameters dialog box of a Gain block, the text box for entering the Gain value contains the expression "x+7" at the inner left edge, and the number 47 at the right edge.

To see the value the variable or expression has during simulation, run the simulation and open the Block Parameters dialog box or the Property Inspector. The displayed value is the value of the variable or expression in the simulation at the time step when you open the Block Parameters dialog box or the Property Inspector.

For more information, see View Values of Parameters Set as Variables.

Consider this example for how to specify the parameter values as variables:

A model contains a Constant block with a Constant value of 1 that connects to a Display block.

Constant block with a value of 1 that connects to a Display block

To specify the Constant value parameter value as the variable expression 2*x+8 with x initialized to a value of 3:

  1. To initialize x, enter this command in the MATLAB Command Window.

    x=3;
  2. To open the Block Parameters dialog box, in the Simulink model window, double-click the Constant block.

  3. In the Block Parameters dialog box, set the Constant value to 2*x+8. On the right side of the text box, the value of the variable expression 2*x+8 is displayed.

    In the Block Parameters dialog box of the Gain block, the text box for entering the Gain value contains the expression "x-1" at the inner left edge, and the number 2 at the right edge.

  4. In the Block Parameters dialog box, click OK.

  5. Run the model. The Display block shows a value of 14.

    A Constant block with a value of 2*x+8 connects to a Display block. The Display block displays a value of 14.

To change the value of x to -1:

  1. Enter this command in the MATLAB Command Window.

    x=-1;
  2. Run the model. The Display block now shows a value of 6.

    A Constant block with a value of 2*x+8 connects to a Display block. The Display block displays a value of 6.

See Also

| |

Related Topics