How can I define conditional units in App Designer?

46 views (last 30 days)
This is my first attempt at App Designer, so pardon my ignorance. I want to provide the user with the option to change between unit systems using a radio button. The execution of that is simple enough, but I am at a loss how to display and change units to accompany the input fields. For example, if the user selects SI units, then the units of the Altitude input should be m, if they choose BG then it should be ft. I started off trying to create simple labels next to the inputs thinking I could make those conditional (if/then), but it's not working out for me. I would really appreciate a shove in the right direction.
Also, it seems from other questions I have reviewed that using super/subscripts in labels is not supported, for example area in m^2. Can anyone confirm if that has changed in R2021 or if that remains unsupported.
HELP!

Accepted Answer

Reshma Nerella
Reshma Nerella on 17 Dec 2021
Hi
Add selectionChanged callback for the button group. Get the button text everytime the value is changed and accordingly change the labels
For instance,
function ButtonGroupSelectionChanged(app, event)
selectedButton = app.ButtonGroup.SelectedObject.Text;
if strcmp(selectedButton, "BG")
% modify labels text according to BG units
app.m2Label.Text = 'm^2';
app.kgsLabel.Text = 'kg/s';
else
% modify labels text according to SI units
app.m2Label.Text = 'x';
app.kgsLabel.Text = 'y';
end
end
Refer to the documentation page to know more about button group callbacks.
Hope this helps!

More Answers (0)

Categories

Find more on Develop Apps Using App Designer in Help Center and File Exchange

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!