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:
Select the block.
Click on the parameter value on the block icon.
Enter a new value.
Press Enter.
Note
The block icon only displays the new value if the value fits on the icon.
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:
Select the Rounding Function block.
Point to the block icon. The editable parameter value appears underlined.
Click the underlined text to edit the value. A list with Function parameter values appears.
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 valuessensor_A
,sensor_B
, andsensor_C
.To change the Goto Tag parameter value of the highlighted Goto and From block pair to a new value:
Select a Goto block, then click on the text on the block icon.
Type in a new name for the tag.
Press Enter.
Select the From block.
Click the text on the block icon. A list with Goto tag parameter values appears.
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:
Select the block.
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.
In the Property Inspector, click the Parameters tab.
On the Parameters tab, find the name of the parameter whose value you want to edit.
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.
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:
Double-click the block. The Block Parameters dialog box appears.
In the Block Parameters dialog box, find the name of the parameter whose value you want to edit.
Edit the parameter value in the corresponding text box. When you edit a parameter value, the text box turns yellow.
Click OK.
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:
Initialize the variable in the MATLAB workspace (base, model, or mask) in which the parameter value is specified.
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.
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.
To specify the Constant value parameter value as the
variable expression 2*x+8
with x
initialized to a
value of 3
:
To initialize
x
, enter this command in the MATLAB Command Window.x=3;
To open the Block Parameters dialog box, in the Simulink model window, double-click the Constant block.
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 expression2*x+8
is displayed.In the Block Parameters dialog box, click OK.
Run the model. The Display block shows a value of
14
.
To change the value of x
to -1
:
Enter this command in the MATLAB Command Window.
x=-1;
Run the model. The Display block now shows a value of
6
.
See Also
Property
Inspector | get_param
| set_param