MATLAB: How to toggle: Making uicontrols (in)visible

visible uicontrol tag

Hi
I want to make a couple edit fields and static texts visible and invisible by using a button/toggle button. But how to do that?
function togglebutton1_Callback(hObject, eventdata, handles)
% hObject handle to togglebutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of togglebutton1
button_state = get(hObject,'Value');
if button_state == get(hObject,'Max')
set(handles.Edit1,'Visible','off')
elseif button_state == get(hObject,'Min')
set(Edit1,'Visible','on')
% Toggle button is not pressed-take appropriate action
...
end

Best Answer

% you've written 'Edit1' instead of 'handles.Edit1'
button_state = get(hObject,'Value');
if button_state == get(hObject,'Max')
set(handles.Edit1,'Visible','off')
elseif button_state == get(hObject,'Min')
set(handles.Edit1,'Visible','on')
end