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.
To create a self-modifying mask using the Mask Editor:
Unlock the library (see Lock and Unlock Libraries).
Right-click the block in the library.
Select Mask > 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 library.
a masked subsystem that modifies its number of input ports based on
a selection made in the subsystem mask dialog box.
Right-click the subsystem and select Mask > Edit Mask. The Mask Editor opens.
The Mask Editor Parameters & Dialog pane
defines a parameter
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 inports list.
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.
This example shows how to force Simulink® to evaluate blocks inside self-modifying masks.
Simulink evaluates elements of models containing masks in the following order:
Mask dialog box
Mask initialization code
Blocks or masked subsystems under the mask
Suppose a block named
myBlock inside subsystem
by a self-modifying mask depends on mask parameter
myParam is exposed to the user through the Mask
Parameters dialog box.
mySubsys is updated
through MATLAB code written in the Mask Initialization pane.
In this model, the sequence of updates is as follows:
myParam through the
mask dialog box.
The mask initialization code receives this change
mySubsys under the mask.
myBlock, which lies under
modifies itself based on the change to
In this sequence, Simulink does not evaluate
which lies under
mySubsys, when the mask initialization
code executes. Instead, Simulink only evaluates and updates the
You can force Simulink to evaluate such blocks earlier
by using the
Simulink.Block.eval method in the initialization
code of the masked subsystem.