Hiding container of a mask using callback/dynamically

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!

카테고리

도움말 센터File Exchange에서 Author Block Masks에 대해 자세히 알아보기

제품

릴리스

R2021a

질문:

2024년 2월 11일

답변:

2024년 9월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by