MATLAB: Change visibility of a frame with a push button

callbackguiguidematlab guipushbuttonvisibility

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!

Best Answer

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