Using the Matlab App Designer, How can I hide a numeric field with a button push?

34 ビュー (過去 30 日間)
Garrett Douglas
Garrett Douglas 2018 年 7 月 11 日
回答済み: Freya H 2018 年 8 月 13 日
I have been attempting to use the Matlab App Designer to create a program GUI. I want to have a button with two options, A or B. If A is selected, a numeric box will pop up with a label, and that numeric will have a variable corresponding to A. If B is selected, I want a different numeric box to pop up, and this box would have a variable associated with B. I am trying to do this within a tab, and do not want to use the figure command as this has created a pop up window. Utilizing an If statement, I have been able to get the boxes to pop up, but if I select button A, and then button B, The button A box does stays open, and the text overlaps. Thank you in advance. App Code Attached:
button = app.ButtonGroup.SelectedObject.Text;
if button(1) == 'A'
% Create EditFieldLabel
appEditFieldLabel = uilabel(app.InputsTab);
appEditFieldLabel.HorizontalAlignment = 'right';
appEditFieldLabel.Position = [210 572 50 15];
appEditFieldLabel.Text = 'A';
% Create EditField
appEditField = uieditfield(app.InputsTab, 'numeric');
appEditField.Position = [275 568 100 22];
delete appEditFieldLabel1
% Create EditFieldLabel
appEditFieldLabel1 = uilabel(app.InputsTab);
appEditFieldLabel1.HorizontalAlignment = 'right';
appEditFieldLabel1.Position = [210 572 50 15];
appEditFieldLabel1.Text = 'B';
% Create EditField
appEditField1 = uieditfield(app.InputsTab, 'numeric');
appEditField1.Position = [275 568 100 22];

回答 (1 件)

Freya H
Freya H 2018 年 8 月 13 日
You can set the visibility of the other label to 'off' using
app.NameofComponent.Visible = 'off'
I would create both components outside the function (e.g. in the design view) and set their visibility to 'off' (e.g. in the startupfcn).
You can then set the visibility of the component you want to show to 'on' in each of your if/else statements (and the other one to 'off').


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





Community Treasure Hunt

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

Start Hunting!

Translated by