Main Content

Dynamic Masked Subsystem

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 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’,‘上’);

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.

金宝app®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.

Creating Self-Modifying Masks Using the Mask Editor

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

  1. Unlock the library (seeLock and Unlock Libraries).

  2. Select the block in the library.

  3. On theBlocktab, in theMaskgroup, clickEdit Mask。掩码编辑器打开。

  4. In the Mask EditorCodepane, select theAllow library block to modify its contentsoption.

  5. Enter the code that modifies the masked subsystem in the maskInitializationpane.

    Do not enter code that structurally modifies the masked subsystem in a dialog parameter callback (seeAdd Mask Code). Doing so triggers an error when you edit the parameter.

  6. ClickApplyto apply the change orOKto 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:

    set_param(gcs,'Lock','off')

  2. Specify that the block is self-modifying by using the following command:

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

    whereblock_nameis the full path to the block in the library.

Create Self-Modifying Mask

图书馆selfModifying_examplecontains a masked subsystem that modifies its number of input ports based on a selection made in the subsystem mask dialog box.

  1. In the Library window, on theLibrarytab, clickLocked Libraryto unlock the library.

  2. On theSubsystem Blocktab, in theMaskgroup, clickEdit Mask。掩码编辑器打开。

  3. The Mask EditorParameters & Dialogpane defines a parameternumInthat stores the value for theNumber of inportsoption. This mask dialog box callback adds or removes Input ports inside the masked subsystem based on the selection made in theNumber of inportslist.

  4. To allow the dialog box callback to function properly, theAllow library block to modify its contentsoption on the Mask EditorCodepane is selected. If this option is not selected, copy of the library block could not modify their structural contents. Also, changing the selection in theNumber of inportslist would produce an error.

Passing Mask Parameter Values from Parent Subsystem to Child Block

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 theset_paramcommand on the child block.

  • Having the child block parameters reference the parent mask parameter name. This is applicable only for the edit parameters.

Related Topics