GUI data Update

조회 수: 1 (최근 30일)
Gerd
Gerd 2011년 3월 8일
Hi guys,
I'm building a gui in matlab and have a question about the guidata update. I want to let the user change a value on a "Edit Text" control and this value changes the current plot function. I wait until the 'return' key is pressed and process the data. The problem is that the user has to hit the return key twice to change the value. I think the guidata is not updated. Does anyone has an advice? Gerd
function txt_Faktor_KeyPressFcn(hObject, eventdata, handles)
% hObject handle to txt_Faktor (see GCBO)
% eventdata structure with the following fields (see UICONTROL)
% Key: name of the key that was pressed, in lower case
% Character: character interpretation of the key(s) that was pressed
% Modifier: name(s) of the modifier key(s) (i.e., control, shift) pressed
% handles structure with handles and user data (see GUIDATA)
if strcmp(eventdata.Key,'return')
handles.Faktor = str2double(get(handles.txt_Faktor,'String'));
% store variable
guidata(hObject,handles);
plotMainWindow(hObject, eventdata, handles);
end

채택된 답변

Walter Roberson
Walter Roberson 2011년 3월 8일
Why are you doing things that way instead of just using a callback function on the edit uicontrol ?
Note by the way, that you should be taking precautions in case the user entered something other than a number.
  댓글 수: 3
Walter Roberson
Walter Roberson 2011년 3월 8일
If you set
uicontrol('Style','edit', 'Callback', @txt_Faktor_Fcn)
then the callback will only be activated if "whenever you activate the uicontrol object (e.g., when you click on a push button or move a slider)" In the case of an edit callback, that occurs when you press return on the control, and does NOT occur if you type into the control but then click outside of the control.
Gerd
Gerd 2011년 3월 8일
Thank you Walter,
the GUI works now fine. Thank you for the explanation.
Gerd

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

추가 답변 (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