How do I set a parameter of a masked subsystem from the parent masked subsystem in Simulink?

20 visualizzazioni (ultimi 30 giorni)

Risposta accettata

MathWorks Support Team
MathWorks Support Team il 19 Ago 2010
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.
  1 Commento
Richard Crozier
Richard Crozier il 24 Gen 2017
Modificato: Richard Crozier il 24 Gen 2017
The example has the command:
set_param('case796589/Subsystem/adder1/Gain','Gain','A')
So you get an error when you use the Subsystem in a new model since the top level simulation is not 'case796589' (see screenshot below).
How do I do this referencing the subsystem blocks relative to the Subsystem so it can be used in a library and be reused?
EDIT:
I think the answer is to use the following instead:
set_param([gcb, '/adder1/Gain'],'Gain','A')

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Subsystems in Help Center e File Exchange

Prodotti

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by