Info
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
Creating GUI - problem with passing on values
조회 수: 1 (최근 30일)
이전 댓글 표시
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
답변 (2개)
Image Analyst
2012년 5월 28일
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
Marek
2012년 5월 29일
댓글 수: 1
Image Analyst
2012년 5월 29일
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.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!