HELP!! MATLAB APP DESIGNER BUTTON PUSH AND PANEL VISIBILITY

38 views (last 30 days)
Hello, I'm working with matlab app designer. I want to design something that when I select the button group, a panel appears. But I cannot do it. I want the panel to appear when I make a selection on the button.
I write app.Panel.Visible = 1; but it didnt work.
classdef app1 < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
ButtonGroup matlab.ui.container.ButtonGroup
Button matlab.ui.control.ToggleButton
end
% Callbacks that handle component events
methods (Access = private)
% Selection changed function: ButtonGroup
function ButtonGroupSelectionChanged(app, event)
selectedButton = app.ButtonGroup.SelectedObject;
app.Panel.Visible=1;
end
end

Answers (1)

Shuba Nandini
Shuba Nandini on 28 Feb 2023
Edited: Shuba Nandini on 28 Feb 2023
Hello,
I understand that you are having trouble with button group and Panel visibility.
According to my research, I have come up with the following steps which can help you to open panel. Your code looks correct but to open a panel when the buttongroup is selected, you must define the property for the panel in the app’s properties section before it’s visibility is set to 1.
Please look at the example below:
classdef app1 < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
ButtonGroup matlab.ui.container.ButtonGroup
Button matlab.ui.control.ToggleButton
Panel matlab.ui.container.Panel % Define a property for the panel
end
% Callbacks that handle component events
methods (Access = private)
% Selection changed function: ButtonGroup
function ButtonGroupSelectionChanged(app, event)
selectedButton = app.ButtonGroup.SelectedObject;
app.Panel.Visible='on'; % Set the visibility of the panel to 'on'
end
end
end
As in above code, Visible Property of panel is set ‘on’ instead of ‘1’. This is because the Visible Property of MATLAB UI Component can either be set ‘on’ or ‘off’.
Refer the below links for more information:
Thanks

Categories

Find more on Develop uifigure-Based Apps in Help Center and File Exchange

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!