"H must be the handle to a figure or figure descendent" error using timers with a GUI

조회 수: 1 (최근 30일)
So I'm trying to make a threshold-crossing interval algorithm to detect ventricular fibrillation and wanted to make a few things (contained in the function "my_callback_function") happen every 1 second. I set up a timer with the line
handles.t=timer('TimerFcn', {@TCIfunc,handles.ecg},'ExecutionMode','FixedRate','Period',1,'StartDelay',1);
The "TCIfunc" function goes as follows:
function TCIfunc(hObject,eventdata,handles)
handles=guidata(handles);
handles.t1==handles.t3;
handles.t3==toc;
tic;
handles.t2_flag==0;
%start(handles.t);
handles.threshold==0.2*handles.max;
handles.max==0;
handles.N == 0;
guidata(handles.ecg, handles);
I declared t1 etc. using handles before creating the timer, in the opening function which includes the timer activation, seen here:
function ecg_OpeningFcn(hObject, eventdata, handles, varargin)
delete (instrfind)
handles.s = serial('COM11');
set(handles.s, 'InputBufferSize', 50); %number of bytes in input buffer
set(handles.s, 'FlowControl', 'none');
set(handles.s, 'BaudRate', 19200);
set(handles.s, 'Parity', 'none');
set(handles.s, 'DataBits',8);
set(handles.s, 'StopBits', 1);
set(handles.s, 'Timeout',1);
handles.threshold_flag=0;
handles.t2_flag=0;
handles.max=0;
handles.threshold=0;
handles.TCI_counter=0;
handles.N=0;
handles.t1=0;
handles.t2=0;
handles.t3=0;
handles.t4=0;
handles.ecg=gcf;
handles.t=timer('TimerFcn', {@TCIfunc,handles.ecg},'ExecutionMode','FixedRate','Period',1,'StartDelay',1);
guidata(handles.ecg,handles);
start(handles.t);
guidata(hObject, handles);
tic;
handles.output = hObject;
guidata(hObject, handles);
varargout{1} = handles.output;
But I keep getting the error: "Error while evaluating TimerFcn for timer 'timer-25'
H must be the handle to a figure or figure descendent." Anyone know what's going on? I'd be very grateful for any help. Full disclosure: I'm relatively new to MATLAB and don't have much idea what I'm doing.
  댓글 수: 3
Nope
Nope 2012년 5월 17일
Thanks, sorry about that. As you can see I've made a little bit of progress, but now I'm getting a different error message.
Daniel Shub
Daniel Shub 2012년 5월 18일
The error refers to H, but I (and Firefox) cannot find H anywhere in the code.

댓글을 달려면 로그인하십시오.

답변 (1개)

Walter Roberson
Walter Roberson 2012년 5월 17일
Please rename your "handles" parameter for your timer function to reflect that you are passing in a figure number rather than a handles structure. You will appreciate the change the next time you go to debug your code after not having looked at it for a day.
Then at the command window, put in
dbstop if error
and run again, and see what you get.
The statement,
handles.ecg=gcf;
Try using
handles.ecg = hObject;
  댓글 수: 7
Nope
Nope 2012년 5월 17일
I do tic in the routine that creates the timer, dunno what that message was about. As I said, it's back to the figure descendents one.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Entering Commands에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by