"H must be the handle to a figure or figure descendent" error using timers with a GUI
1 view (last 30 days)
Show older comments
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 Comments
Daniel Shub
on 18 May 2012
The error refers to H, but I (and Firefox) cannot find H anywhere in the code.
Answers (1)
Walter Roberson
on 17 May 2012
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 Comments
See Also
Categories
Find more on Entering Commands in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!