Enable/disable dropdowns when checkbox checked/unchecked in MATLAB2019A app designer
Show older comments
I want to disable the given dropdown if the checkbox is selected and enable it once checkbox is unchecked.
How should be the code?
Answers (1)
Kojiro Saito
on 6 Nov 2019
First, add ValueChangedFcn callback from app.CheckBox.

Then, define CheckBoxValueChanged function as the follows.s
% Value changed function: CheckBox
function CheckBoxValueChanged(app, event)
value = app.CheckBox.Value;
if value == true
% If checkbox is checked, make dropdown disable
app.DropDown.Enable = false;
else
% If checkbox is unchcked, make dropdown enable
app.DropDown.Enable = true;
end
end
Here is a screenshot.

9 Comments
Paolo Volpe
on 17 Nov 2022
Hello there,
I tried to make the same example you did and it doesn't work. Any alternative solutions?
Error: Invalid expression. Check for missing multiplication operator, missing or unbalanced delimiters, or other syntax error. To construct matrices, use brackets instead of parentheses.
Kojiro Saito
on 17 Nov 2022
Possibly, the syntax might be uncomplete . Could you show your callback function?
Paolo Volpe
on 17 Nov 2022
Moved: Kojiro Saito
on 17 Nov 2022
@Kojiro Saito I just made the same passages you made in the script. I show you my steps:
- I created a new APP Designer script
- I added the checkBox and the DropDown icon
- I added the callbacks
- Here you find the code I put in the callbacks
% Value changed function: CheckBox
function CheckBoxValueChanged(app, event)
value = app.CheckBox.Value;
if value == true
app.DropDown.Enable = false;
else
app.DropDown.Enable = true;
end
end
Kojiro Saito
on 17 Nov 2022
Edited: Kojiro Saito
on 17 Nov 2022
Do app.Checkbox and app.DropDown match the existing components?
In my previous answer, there are app.Checkbox and app.DropDown under app.UIFigure.

How do your components look like?
Paolo Volpe
on 17 Nov 2022
Edited: Paolo Volpe
on 17 Nov 2022
This is how they look like

And this is the resulting error:

Kojiro Saito
on 17 Nov 2022
OK, I found the reason.
Please delete the "end" in the last line. This occurs syntax error.

Paolo Volpe
on 17 Nov 2022
Thank you, I didn't notice the end of the function
Paolo Volpe
on 17 Nov 2022
If I want to save my output file from the APP designer which function can I use? I didn't find nothing correlated to my question on the web. Thank you
Kojiro Saito
on 17 Nov 2022
You can use save (as .mat file), writetable (as .csv or .txt, .xlsx) and so on.
Categories
Find more on Startup and Shutdown in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!