MATLAB: How to set a parameter of a masked subsystem from the parent masked subsystem in Simulink

"hiddenchangedynamicmaskedparameterparentsetsimulinksubsystemx

I would like to set a parameter of a masked subsystem from the parent masked subsystem in Simulink.

Best Answer

An example model and library model are available to demonstrate how to do this. Download the change.mdl and mylib.mdl files attached at the bottom of the page.
1. Open the change.mdl model and right-click on the 'Subsystem' block. Select 'Edit mask' and then go to the initialization tab. Look at the SET_PARAM command. The change.mdl model allows you to change the value of the Gain block in the lower subsystem by adjusting a value in the mask dialog of the parent subsystem. Note that the block is refered to by its complete path.
2. Drag the Subsystem block from the 'mylib' library into a new model. Click on the block in the model and then execute the following command from the MATLAB command line:
get_param(gcb,'MaskSelfModifiable')
Notice that the parent Subsystem mask's 'selfmodifiable' property is turned 'on'. It is this property that allows the block to modify a parameter in the lower subsystem without breaking the library link or unlocking the library. The command used to set the library block's 'selfmodifiable' property is
set_param(gcb,'MaskSelfModifiable','on')
3. Save the model.
4. Drag this block back into the library. You receive a message that you are modifying a locked library. Select to unlock the library and replace the original block with the one you just saved. Then resave the library to lock it once again.
5. Close your Simulink browser and reopen it to see the changes in your browser.
Now you should be able to drag this modified block into any model, and change the lower subsystem's parameters from the parent subsystem's mask.