This check box is enabled only if the masked subsystem resides in a library. Checking this option allows the block initialization code to modify the contents of the masked subsystem (that is, it lets the code add or delete blocks and set the parameters of those blocks). Otherwise, an error is generated when a masked library block tries to modify its contents in any way. To set this option at the MATLAB® prompt, select the self-modifying block and enter the following command.
set_param(gcb, 'MaskSelfModifiable', 'on');
Then save the block.
You can create masked library blocks that can modify their structural contents. These self-modifying masks allow you to:
Modify the contents of a masked subsystem based on parameters in the mask dialog box or when the subsystem is initially dragged from the library into a new model.
Vary the number of ports on a multiport S-Function block that resides in a library.
Simulink® runs the mask-initialization code for a self-modifiable library block when you load the block. If the mask-initialization code controls the number of input/output ports for a block, mark the block as self-modifiable. Otherwise, the mask-initialization code will not execute and will not set the right number of ports, which will disconnect the block.
To create a self-modifying mask using the Mask Editor:
Unlock the library (see Lock and Unlock Libraries).
Select the block in the library.
On the Block tab, in the Mask group, click Edit Mask. The Mask Editor opens.
In the Mask Editor Initialization pane, select the Allow library block to modify its contents option.
Enter the code that modifies the masked subsystem in the mask Initialization pane.
Do not enter code that structurally modifies the masked subsystem in a dialog parameter callback (see Add Mask Code). Doing so triggers an error when you edit the parameter.
Click Apply to apply the change or OK to apply the change and close the Mask Editor.
Lock the library.
To create a self-modifying mask from the command line:
Unlock the library using the following command:
Specify that the block is self-modifying by using the following command:
block_name is the full path to the block in the
contains a masked subsystem that modifies its number of input ports based on a
selection made in the subsystem mask dialog box.
In the Library window, on the Library tab, click Locked Library to unlock the library.
On the Subsystem Block tab, in the Mask group, click Edit Mask. The Mask Editor opens.
The Mask Editor Parameters & Dialog pane defines a
numIn that stores the value for the Number of
inports option. This mask dialog box callback adds or removes Input ports
inside the masked subsystem based on the selection made in the Number of
To allow the dialog box callback to function properly, the Allow library block to modify its contents option on the Mask Editor Initialization pane is selected. If this option is not selected, copy of the library block could not modify their structural contents. Also, changing the selection in the Number of inports list would produce an error.
You can pass mask parameter values from a parent subsystem to a child block in three ways:
Using parameter promotion.
Using the mask initialization code. This is done by using the
set_param command on the child block.
Having the child block parameters reference the parent mask parameter name. This is applicable only for the edit parameters.