Change visibility of a frame with a push button

5 views (last 30 days)
Hello! My task is to change the visibility of a frame with a push button. If the frame is visible, clicking the button should make it invisible and vice versa. Here is the code of the callback function for the pushbutton.
function pushbutton4_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
visibility = get(handles.uibuttongroup5, 'Visible')
if visibility == 'on'
set(handles.uibuttongroup5, 'Visible', 'off')
else
set(handles.uibuttongroup5, 'Visible', 'on')
end
And I am getting this error:
Matrix dimensions must agree.
Error in guiassign>pushbutton4_Callback (line 346)
if visibility == 'on'
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in guiassign (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)guiassign('pushbutton4_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback.
>>
Can someone help me with that please?
Thank you!

Accepted Answer

Stephen23
Stephen23 on 17 Oct 2017
Edited: Stephen23 on 17 Oct 2017
You should use strcmpi to compare, not logical equivalence (which compares arrays element-wise):
if strcmpi(visibility,'on')

More Answers (0)

Categories

Find more on Migrate GUIDE Apps 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!