Dynamic Masked Subsystem
Allow Library Block to Modify Its Contents
The option Allow mask initialization code to modify the subsystem's content 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). This checkbox is enabled only when the block resides in a library or the subsystem reference having a system mask. 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.
Create Self-Modifying Masks for Library Blocks
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.
Creating Self-Modifying Masks Using the Mask Editor
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 Code pane, select the Allow mask initialization code to modify the subsystem's content 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.
Creating Self-Modifying Masks from the Command Line
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_nameis the full path to the block in the library.
Create Self-Modifying Mask
In this example if you change the Time domain on the mask dialog box, the block within the Subsystem is replaced accordingly. For example, if you select the Time domain as Discrete, the Integrator block is replaced with a Discrete-Time Integrator block and vise-versa.
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 parameter
Time domainthat stores the value for the time option. This mask dialog box callback replaces the Integrator block with a Discrete-Time Integrator block and vise-versa.
To allow the dialog box callback to function properly, the Allow mask initialization code to modify the subsystem's content option on the Mask Editor Code 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 Time Domain list would produce an error.