The masking_examplemasking_example assigns the values input using the mask dialog box directly to block parameters underneath the mask, as described in How Mask Parameters Work. The assignment occurs because the block parameter and the mask parameter have the same name, so the search that always occurs when a block parameter needs a value finds the mask parameter value automatically, as described in Symbol Resolution.
You can use the Mask Editor to insert any desired calculation between a value in the mask dialog box and an underlying block parameter:
See the Initialization Pane reference for reference information about all Initialization pane capabilities. This section shows you how to use it for calculating block parameter values.
To calculate a value for a block parameter, first break the link between the mask and block parameters by giving them different names. To facilitate such changes, the Dialog variables subpane lists all mask parameters. The Initialization pane looks like this:
You cannot use mask initialization code to change mask parameter default values in a library block or any other block.
You can use the initialization code for a masked block to link mask parameters indirectly to block parameters. In this approach, the initialization code creates variables in the mask workspace whose values are functions of the mask parameters and that appear in expressions that set the values of parameters of blocks concealed by the mask.
If you need both the string entered and the evaluated value, clear the Evaluate option. To get the value of a base workspace variable entered as the literal value of the mask parameter, use the MATLAB® evalin command in the mask initialization code. For example, suppose the user enters the string 'gain' as the literal value of the mask parameter k where gain is the name of a base workspace variable. To obtain the value of the base workspace variable, use the following command in the initialization code for the mask:
value = evalin('base', k)
These values are stored in variables in the mask workspace. A masked block can access variables in its mask workspace. A workspace is associated with each masked subsystem that you create. The current values of the subsystem's parameters are stored in the workspace as well as any variables created by the block's initialization code and parameter callbacks.
To use a masked subsystem in a referenced model that uses model arguments, do not create in the mask workspace a variable that derives its value from a mask parameter. Instead, use blocks under the masked subsystem to perform the calculations for the mask workspace variable.