GUI data Update
1 view (last 30 days)
Show older comments
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 Comments
Accepted Answer
Walter Roberson
on 8 Mar 2011
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 Comments
Walter Roberson
on 8 Mar 2011
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.
More Answers (0)
See Also
Categories
Find more on Migrate GUIDE Apps in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!