Products & Services Solutions Academia Support User Community Company

Learn more about Simulink   

Creating Dynamic Masked Subsystems

Allow library block to modify its contents

This check box is enabled only if the masked subsystem resides in a library. Checking this option allows the block's initialization code to modify the contents of the masked subsystem, i.e., 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.

Creating 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

Creating Self-Modifying Masks Using the Mask Editor

To create a self-modifying mask using the Mask Editor:

  1. Unlock the library (see Modifying a Library).

  2. Select the block in the library.

  3. Select Edit Mask from the Edit menu or the block's context menu. The Mask Editor opens.

  4. In the Mask Editor's Initialization pane, select the Allow library block to modify its contents option.

  5. Enter the code that modifies the masked subsystem in the mask's Initialization pane.

      Note   Do not enter code that structurally modifies the masked subsystem in a dialog parameter callback (see ). Doing so triggers an error when a user edits the parameter.

  6. Click Apply to apply the change or OK to apply the change and dismiss 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:

    set_param(gcs,'Lock','off')
  2. Specify that the block is self-modifying by using the following command:

    set_param(block_name,'MaskSelfModifiable','on')

    where block_name is the full path to the block in the library.

Self-Modifying Mask Example

The library selfModifying_example.mdl contains a masked subsystem that modifies its number of input ports based on a selection made in the subsystem's Mask Parameters dialog box.

Select the subsystem then select View Mask from the Edit menu or the block's context menu. The Mask Editor opens. The Mask Editor's Parameters pane defines one mask parameter variable numIn that stores the value for the Number of inports option. This Mask Parameters 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 callback to function properly, the Allow library block to modify its contents option on the Mask Editor's Initialization pane is selected. If this option were not selected, copies of the library block could not modify their structural contents and changing the selection in the Number of inports list would produce an error.

  


Related Products & Applications

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS