Info
This question is closed. Reopen it to edit or answer.
Creating GUI - problem with passing on values
1 view (last 30 days)
Show older comments
Hello, I hope tilte of this question won't be mislead anyone.
I'm creating GUI, which uses some numerical data for further action. I have created several fields to input data:
function xxx_Callback(hObject, eventdata, handles)
xxx = str2double(get(hObject,'string'));
if isnan(xxx)
errordlg('You must enter a numeric value','Bad Input','modal')
uicontrol(hObject)
return
end
guidata(hObject,handles);
Let's assume there is 3 of them (xxx, yyy, zzz) built in the same manner. Additionally, I set up pushbutton, which should extract this values to 3 variables, and create matrix 1x3.
xxx= str2num(get(handles.xxx,'string')); yyy= str2num(get(handles.yyy,'string')); zzz= str2num(get(handles.zzz,'string'));
input = [xxx yyy zzz]; set(handles.xxx,'string',''); % resets edit set(handles.xxx,'string',''); % resets edit set(handles.xxx,'string',''); % resets edit guidata(hObject,handles);
Unfortunately, Matlab is not working as expected, it points me error that states:
"Error in ==> odczyt at 1 xxx = str2num(get(handles.xxx,'string'));
Error in ==> gui_temp>AAAA_method_Callback at 473 odczyt;
Error in ==> gui_mainfcn at 96 feval(varargin{:});
Error in ==> gui_temp at 42 gui_mainfcn(gui_State, varargin{:});
Error in ==> @(hObject,eventdata)gui_temp('AAAA_method_Callback',hObject,eventdata,guidata(hObject))
??? Error while evaluating uicontrol Callback"
Where "AAAA_method' is the name of this pushbutton.
Where is the problem in this code or idea? Thank you in advance for your ideas and comments.
Best regards, Marek
0 Comments
Answers (2)
Image Analyst
on 28 May 2012
I don't know why you call uicontrol() in the callback. What's the point of that? I think it will create a brand new control. As a matter of fact, that's probably why you're getting your error message. You've just blown away everything it knows about your control, including the callback function.
Do you want to just clear the edit field of whatever the user typed in? If so, use set(handles.xxx, 'String', []). And don't use "input" for your variable name - it's already a built in function and you'll destroy it by creating a variable of your own with the same name.
0 Comments
Marek
on 29 May 2012
1 Comment
Image Analyst
on 29 May 2012
Is you max property more than 1 for the edit text box? If so, you might be returning a cell array instead of a string, and might have to use cell2mat instead of str2double.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!