How can I define conditional units in App Designer?

10 ビュー (過去 30 日間)
Matt Brown
Matt Brown 2021 年 12 月 13 日
回答済み: Reshma Nerella 2021 年 12 月 17 日
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!

採用された回答

Reshma Nerella
Reshma Nerella 2021 年 12 月 17 日
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!

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDevelop Apps Using App Designer についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by