MATLAB: How to make a tool invisible when a condition of a group of switches are “off “

app designervisible component

Hello
everyone,
I have a question I am not sure how to hide the elements in the blue box when all or some of the swichtes in the red boxes are in "on" position
I tierd to do these
% under each "switch value changed"
value = app.Switch_Gray_Sp.Value;
if strcmp(app.Switch_Gray_Sp.Value, 'On')
app.gz =0;
else strcmp(app.Switch_Gray_Sp.Value, 'Off')
app.gz=1;
end
% I repeated this for all three colors
% then, under pick a file drop dwon menu for all speakers
sum = app.rz+app.bz+app.grz+app.gz;
if (sum==4)
app.PickAFileDropDown_All_Sp.Visible = 'off' ;
app.OverallVolumeSlider.Visible = 'off' ;
else (sum<4)
app.PickAFileDropDown_All_Sp.Visible = 'on' ;
app.OverallVolumeSlider.Visible = 'on' ;
end
% also, I tried to do this at the "startupFun(app)"
if strcmp(app.Switch_Red_Sp.Value, 'On') || strcmp(app.Switch_Black_Sp.Value, 'On') || strcmp(app.Switch_Gray_Sp.Value, 'On') || strcmp(app.Switch_Green_Sp.Value, 'On')
app.PickAFileDropDown_All_Sp.Visible = 'off' ;
app.OverallVolumeSlider.Visible = 'off' ;
else strcmp(app.Switch_Red_Sp.Value, 'Off') && strcmp(app.Switch_Black_Sp.Value, 'Off') && strcmp(app.Switch_Gray_Sp.Value, 'Off') && strcmp(app.Switch_Green_Sp.Value, 'Off')
app.PickAFileDropDown_All_Sp.Visible = 'on' ;
app.OverallVolumeSlider.Visible = 'on' ;
end
I believe that my executions are in the wong place
Can you help with that please.

Best Answer

You just need to set the visible property to 'off' to hide a control.
Where you do this depends on the behavior you want. When the conditions are met, turn the visible property to off.
You code makes sense to me, but it would be easier if you included at least the function declaration of where the code sections are coming from. It looks like the code that actually turns the visibility off is placed under the drop down list in each section. It would make more sense to me to place this in the switch callback, as that is what triggers hiding the blue box.
Callbacks are run in reponse to an interaction with a control. Any code you want to execute in response to that interaction needs to be in that callback (or initiated from it).
So the code you comment with " % then, under pick a file drop dwon menu for all speakers" won't run until the user interacts with the drop down menu.