Mask a Subsystem File
Add a System Mask to a Subsystem File
You can mask a subsystem file using a system mask. When you create a system mask for a subsystem file, all the referenced instances share the same system mask.
To mask a subsystem file:
Open the subsystem file to be masked.
In the Simulink® toolstrip, on the Subsystem tab, click Create System Mask. Alternatively, right-click anywhere on the canvas and select Mask and click Create System Mask. The Mask Editor dialog opens.
Add mask parameters and click OK.
Note
You cannot directly mask a Subsystem Reference block. To mask a Subsystem Reference block, select the block. On the Referenced Subsystem tab, click Create System Mask. This action opens the subsystem file being referenced and creates a mask on it.
You cannot set parameters using
set_param
in a call back code of a masked subsystem. However if the subsystem is self-modifiable or referenced from a library you can set the parameters.
For more information on creating and editing system masks, see Introduction to System Mask.
Create Self-Modifiable Subsystem Reference Using System Mask
You can make instance-specific changes in the contents of a masked subsystem file using the system mask. To allow dynamic changes, set the masked subsystem file as self-modifiable. In a self-modifiable subsystem file, you can use the initialization callback of the system mask to add or delete blocks and set the parameters of the blocks within the file.
To set a masked subsystem file as self-modifiable, in the subsystem file, go to the Code tab of the System Mask Editor and select Allow mask initialization code to modify the subsystem's content.
You can also set the masked subsystem file ssref
as self-modifiable
programmatically. First, get the subsystem file mask as a mask object. Then set the masked
subsystem file as
self-modifiable.
maskObj = Simulink.Mask.get("ssref"); maskObj.SelfModifiable = 'on';
In a self-modifiable masked subsystem file, you can modify the blocks of a masked subsystem reference instance or allow the masked subsystems inside a masked subsystem reference instance to self-modify.
Modify Blocks of a Masked Subsystem Reference
Consider a self-modifiable masked subsystem file ssref1
that
includes a Gain block. The system mask of the subsystem reference instance
SR1
uses Gain as the mask parameter to set the
value of the Gain block. To dynamically set the block's value from the
system mask, the mask initialization callback of ssref1
first gets the
Gain parameter value from the system mask and then sets the value
of the Gain block inside the subsystem reference instance.
Allow Masked Subsystems Inside a Masked Subsystem Reference to Self-Modify
Consider a self-modifiable masked subsystem file ssref2
that
includes a masked subsystem Subsystem-1
. Further,
Subsystem-1
includes a Gain block. Subsystem reference
instance SR3
and masked subsystem Subsystem-1
use
Gain as the mask parameter to set the value of the
Gain block. To dynamically set the block's value from the system mask,
the mask initialization callback of Subsystem-1
gets the
Gain parameter value from the system mask. The mask initialization
callback of ssref2
gets the Gain parameter value
from the parent subsystem Subsystem-1
mask and then sets the value of
the Gain block.
Considerations
There are certain cases where you cannot use a callback to modify the contents of a subsystem reference instance even with a self-modifiable mask.
If you want to modify a block located inside a Subsystem Reference, you cannot use callback of a top model or block that is higher in the model hierarchy than the Subsystem Reference.
If the block you want to modify is inside a masked subsystem of a Subsystem Reference, you must use the mask callback of the parent masked subsystem. Using the callback of any other block to modify a block within a masked subsystem of a Subsystem Reference is not feasible.