Main Content

Pass Values to Blocks Under the Mask

A masked block can pass values to the block parameters under the mask. The underlying blocks use the passed values during simulation to execute the block logic.

A masked block has variables associated with mask parameters. These variables are stored in the mask workspace for a model and can correspond to a block parameter under the mask. When such a block is evaluated, the block variables look for matching values in the mask workspace to get a value.

The mapping of variables from the mask workspace to the base workspace must be correct. A correct mapping ensures that the right block variable is assigned the value that is passed from the mask.

Use any of these options to pass values to blocks under the mask:

  • Parameter promotion (recommended)

  • Mask initialization

  • Referencing block parameters using variable names (For the Edit Parameter only)

Parameter Promotion

When you promote a block parameter to its mask, the block parameter becomes accessible from the mask dialog box, allowing you to pass a value for the block parameter. Parameter promotion ensures correct mapping of parameter values and is a recommended way to pass values to the block from the mask dialog box. Note that, when you promote parameters of an in-built block, the internal callbacks associated with these parameters are also inherited in the new parameter. For more information on promoting a parameter, see Promote Block Parameters on a Mask.

Mask Initialization

You can use MATLAB® code in the Initialization pane of the Mask Editor to assign or pass values to the block parameters under the mask. You can assign a fixed value to a block parameter, specify an acceptable range for the input values, or specify a value for the child block. For more information, see Get Started with Mask Initialization and Callback Code.

Referencing Block Parameters Using Variable Names

You can add an Edit parameter to the mask dialog box and pass values to the block parameters through it. The values that you provide for the Edit parameter in the mask dialog box automatically becomes associated with the block parameter, by using the techniques described in Symbol Resolution.

Consider the model, which contains a masked Subsystem block and governs the equation y = mx + b. Here, m and b are variables controlling the slope and intercept of the equation and are associated with the Gain and the Constant block, respectively.

line equation

The variables m and b are assigned to the mask parameters Slope and Intercept, respectively, as parameter names in the Mask Editor.

mask editor line equation

When you type values for Slope and Intercept in the mask dialog box, these values are internally assigned to the variables m and b. When the model is simulated, the Gain block and the Constant block search for numeric values of m and b and apply them to resolve the equation y = mx + b.

Related Topics