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

7 ビュー (過去 30 日間)
Hamid
Hamid 2015 年 12 月 2 日
コメント済み: Hamid 2015 年 12 月 2 日
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
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.
Hamid
Hamid 2015 年 12 月 2 日
Ok, I will check that documents in other time.
Thanks.

サインインしてコメントする。

採用された回答

Adam
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 ExchangeMigrate GUIDE Apps についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by