Undefined function or variable ... Error while evaluating uicontrol Callback
6 次查看(过去 30 天)
显示 更早的评论
Hi everyone, I'm using GUI tool.
I'm going to enter my inputs from menu but I got this error :
??? Undefined function or variable 'I'.
Error in ==> GUI_2>Calculate_Callback at 379
A=I/sqrt(((TCAP*10^-4)/(tc*ar*pr))*log((k0+Tm)/(k0+Ta)));
Error in ==> gui_mainfcn at 96
feval(varargin{:});
Error in ==> GUI_2 at 42
gui_mainfcn(gui_State, varargin{:});
Error in ==> @(hObject,eventdata)GUI_2('Calculate_Callback',hObject,eventdata,guidata(hObject))
??? Error using ==> drawnow
Error while evaluating uicontrol Callback
this is my code (short version) :
...
function Untitled_1_Callback(hObject, eventdata, handles)
% hObject handle to Untitled_1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
prompt = {'rms symmetrical line to ground fault current in kA:'};
title = 'Ground Grid Inputs';
lines = 0.8;
def = {''};
options.Resize='on';
options.WindowStyle='normal';
options.Interpreter='tex';
answer=str2double(inputdlg(prompt,title,lines,def,options));
I=answer(1);
...
% --- Executes on button press in Calculate.
function Calculate_Callback(hObject, eventdata, handles)
A=I/sqrt(((TCAP*10^-4)/(tc*ar*pr))*log((k0+Tm)/(k0+Ta)));
WHAT SHOULD I DO??
pleaseeeeeeeeeee
4 个评论
Adam
2015-12-2
The workspace for Untitled_1_Callback is completely separate from the workspace of Calculate_Callback. This is why when you asked this question previously with a lot of the key code missed out it did not make sense why 'I' should be undefined when you use it.
采纳的回答
Adam
2015-12-2
handles.I = answer(1);
guidata( hObject, handles );
in your first callback and
I = handles.I;
at the start of your second callback will fix this in a simple way, but I strongly advise you to read up on this, following the links Stephen suggested. Using guidata is very easy when you are used to it and actually understand it, but it also has pitfalls if you simply copy examples of it without properly understanding what it is doing and why.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Interactive Control and Callbacks 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!