Undefined function or variable ... Error while evaluating uicontrol Callback

8 views (last 30 days)
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 Comments
Adam
Adam on 2 Dec 2015
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.

Sign in to comment.

Accepted Answer

Adam
Adam on 2 Dec 2015
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.

More Answers (0)

Categories

Find more on Interactive Control and Callbacks in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!