MATLAB Answers

How to toggle: Making uicontrols (in)visible

Asked by Hello kity on 31 Dec 2012

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 

  0 Comments

Products

No products are associated with this question.

1 Answer

Answer by Azzi Abdelmalek
on 31 Dec 2012
Edited by Azzi Abdelmalek
on 31 Dec 2012
 Accepted 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

  2 Comments

Hello kity on 2 Jan 2013

how can i make that edit1 field a NaN if the edit field is not visible?

str2double(get(handles.Edit1,'String'))=NaN;

Azzi Abdelmalek
on 2 Jan 2013

Why are you using get?

set(handles.Edit1,'string','nan')

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply today