Error in Timer function

2 ビュー (過去 30 日間)
Karthik KJ
Karthik KJ 2012 年 7 月 13 日
Hi I am just testing how Timer function works in GUI. I have an older script from google search.
Basically i have created an timer and when the gui opens it should update the edit box with an random number.
function figure1_CreateFcn(hObject, eventdata, handles)
handles.guifig = gcf
handles.tmr = timer('TimerFcn',...
{@TmrFcn,handles.guifig},'BusyMode','Queue',...
'ExecutionMode','FixedRate','Period',2);%timer updating after every 2 secs
guidata(handles.guifig,handles);
start(handles.tmr);
guidata(hObject, handles);
%Timer Function
function TmrFcn(src,event,handles) %Timer function
handles = guidata(handles)
x = rand%define your function here
set(handles.edit1,'value',num2str(x));
guidata(handles.guifig, handles);
Im getting error ' Reference to non-existent field 'edit1'.
Can any one help me in solving this.
  1 件のコメント
TAB
TAB 2012 年 7 月 13 日
Karthik, please format your code. See markup help.

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

回答 (2 件)

Image Analyst
Image Analyst 2012 年 7 月 13 日
In GUIDE, look at the "Tag" property of the edit fields on your GUI. You don't have any that have the "tag" of "edit1".
  2 件のコメント
Karthik KJ
Karthik KJ 2012 年 7 月 13 日
I have checked no issue with the tag property. Sorry I forgot to add the full error
??? Error while evaluating TimerFcn for timer 'timer-17'
Reference to non-existent field 'edit1'.
Image Analyst
Image Analyst 2012 年 7 月 14 日
編集済み: Image Analyst 2012 年 7 月 14 日
Same answer. See where it says "Reference to non-existent field 'edit1'." The variable "handles" exists but it has no field called edit1. That means you don't have a control on your GUI called edit1, just like I first said. Look again at the tag property of all your edit fields on your GUI.

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


Sean de Wolski
Sean de Wolski 2012 年 7 月 13 日
編集済み: Sean de Wolski 2012 年 7 月 13 日
Is this occuring because you close the GUI without stopping the timer?
In the closeRequestFcn of the GUI, be sure to have a:
t = timerfindall;
is ~isempty(t)
stop(t);
delete(t);
end
  2 件のコメント
Sean de Wolski
Sean de Wolski 2012 年 7 月 13 日
Nevermind. Probably not the case because the field doesn't exist. You would get an error "invalid or deleted object" here I would think.
Image Analyst
Image Analyst 2012 年 7 月 14 日
編集済み: Image Analyst 2012 年 7 月 14 日
I agree with Sean - and the field does not exist because the edit text box called "edit1" (meaning the tag property = edit1) simply does not exist on the GUI.

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

カテゴリ

Help Center および File ExchangeEnvironment and Settings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by