How to toggle: Making uicontrols (in)visible

조회 수: 8 (최근 30일)
Hello kity
Hello kity 2012년 12월 31일
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

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2012년 12월 31일
편집: Azzi Abdelmalek 2012년 12월 31일
% 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
Hello kity
Hello kity 2013년 1월 2일
편집: Hello kity 2013년 1월 2일
how can i make that edit1 field a NaN if the edit field is not visible?
str2double(get(handles.Edit1,'String'))=NaN;
Azzi Abdelmalek
Azzi Abdelmalek 2013년 1월 2일
Why are you using get?
set(handles.Edit1,'string','nan')

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by