Hiding container of a mask using callback/dynamically

6 次查看(过去 30 天)
I am working to create a dynamic mask for a subsystem (refer image below).
Fig 1
I want to hide Specification 2- Specification 7 using callback (or any other method) in mask if "No. of models" is "1".
I cannot hide it like other mask parameters such as Voc1 using callback (refer code).
Error: Property assignment is not allowed when the object is empty.  Use subscripted assignment to create an array element.
Fig 2
Please suggest how to proceed.

回答(1 个)

Rajanya
Rajanya 2024-9-18
I understand that you are trying to control the visibility of containers based on a popup parameter value. I was able to create a dummy mask like your custom mask with two containers (with names ‘Container3’ and ‘Container4’ under the prompt of ‘Specification1’ and ‘Specification2’ respectively) and a popup field (‘No. of models’) which can get populated with values 1 and 2 as shown below:
Containers, unlike mask parameters, need to be accessed by the ‘getDialogControl’ method from the ‘Simulink.dialog.Container’ class. For this, a mask object must be created first, like:
maskobj = Simulink.Mask.get(gcb);
The container properties can then be accessed via:
maskobj.getDialogControl(<container_name>);
The code below demonstrates how to control the visibility of ‘Specification1’ based on the popup parameter value with name ‘Parameter1’ and prompt ‘No. of models’. It hides ‘Specification1’ when ‘No. of models’ is anything other than 1.
selectedVal = get_param(gcb,'Parameter1')
if strcmp(selectedVal,'1')
maskobj.getDialogControl('Container3').Visible = 'on';
else
maskobj.getDialogControl('Container3').Visible = 'off';
end
You can also modify the ‘OpenFcn’ callback parameter of the block under Properties > Callbacks > OpenFcn accordingly in a similar fashion to add a callback functionality to the subsystem.
Refer to the following resources for more information:
Hope this helps!

类别

Help CenterFile Exchange 中查找有关 Author Block Masks 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by