GUI data Update
조회 수: 1 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
채택된 답변
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
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.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!