What caused GUI problem after Push Button is pressed and any recommended solution?
1 次查看(过去 30 天)
显示 更早的评论
Hi. I have a GUI problem.
Here is code for the Push Button.
function runButton_Callback(hObject, eventdata, handles)
% selects graph1 as the current axes, so that
% Matlab knows where to plot the data
axes(handles.graph1)
range_find(pt, tau, fr, time_ti, gt, gr, freq, ...
sigma, te, nf, loss, snro, range, out_option);
guidata(hObject, handles); % updates the handles
This is the code for the edit text for Pt
function ptEdit_Callback(hObject, eventdata, handles)
pt = str2num(get(hObject,'String'));
% checks to see if input is empty. if so, default input1_editText to 100
if (isempty(pt))
set(hObject,'String','100')
pt = str2num(get(hObject,'String'));
msgbox('Please enter number only')
end
guidata(hObject, handles);
function ptEdit_CreateFcn(hObject, eventdata, handles)
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
When I run the GUI, I have the following error message ??? Undefined function or variable 'pt'.
Error in ==> mark_v1>runButton_Callback at 86 range_find(pt, tau, fr, time_ti, gt, gr, freq, ...
Error in ==> gui_mainfcn at 96 feval(varargin{:});
Error in ==> mark_v1 at 42 gui_mainfcn(gui_State, varargin{:});
Error in ==> @(hObject,eventdata)mark_v1('runButton_Callback',hObject,eventdata,guidata(hObject))
??? Error while evaluating uicontrol Callback
What can I do to overcome this problem? Any advice regarding this matter is highly appreciated. Thanks.
0 个评论
采纳的回答
Walter Roberson
2011-12-19
4 个评论
Walter Roberson
2011-12-20
If you already assign to handles.pt in ptEdit_Callback then you do not need to assign pt to handles.pt in runButton_Callback -- but you do need to ensure that runButton_Callback is not called until after ptEdit_Callback, such as by setting runButton to 'Enable', 'off' at the beginning of the program, and only setting it to 'Enable' 'on' after ptEdit_Callback has checked the data and verified that the user-entered pt value is valid. (You should be checking for bad data in ptEdit_Callback; at minimum you should check that the str2num did not return [] or NaN. And it is better and much more secure to use str2double() than str2num
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!