MATLAB Answers

Hamid
0

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

Asked by Hamid
on 2 Dec 2015
Latest activity Commented on by Hamid
on 2 Dec 2015

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

Show 1 older comment

Can you write the right code for me please?

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.

Ok, I will check that documents in other time.

Thanks.

Log in to comment.

Tags

1 Answer

Answer by Adam
on 2 Dec 2015
 Accepted Answer

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.


Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today