Dynamic Masked Subsystem
Create masked library blocks that can modify their structural contents.
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). To set this option at the MATLAB® prompt, select the self-modifying block and enter the following command and then save the block.
set_param(gcb, 'MaskSelfModifiable', 'on');
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:
1. Unlock the library. See Lock and Unlock Libraries
2. Select the block in the library.
3. On the Block tab, in the Mask group, click Edit Mask. The Mask Editor opens.
4. In the Mask Editor Code pane, select the Allow mask initialization code to modify the subsystem's content option.
5. 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.
6. Click Apply to apply the change or Ok to apply the change and close the Mask Editor.
7. Lock the library.
Creating Self-Modifying Masks from the Command Line
To create a self-modifying mask from the command line:
1. Unlock the library using the following command:
2. Specify that the block is self-modifying by using the following command:
where, block_name is 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.
1. In the Library window, on the Library tab, click Locked Library to unlock the library.
2. On the Subsystem Block tab, in the Mask group, click Edit Mask. The Mask Editor opens.
3. The Mask Editor Parameters & Dialog pane defines a parameter
Time domain that 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.
4. 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.