TimerFcn in gui from one function to another

조회 수: 1 (최근 30일)
Cait
Cait 2012년 7월 16일
I have a gui that interfaces with some TDT software to play out electrical stimuli. I want to have an intertrial interval using a timer between trials. Essentially the timer is called at the end of a function and the TimerFcn is to call a different function.
So far, I have gone with creating the timer in the OpeningFcn:
%PUTTING IN THE TIMER
handles.gotimer = timer('TimerFcn',@(hObject,eventdata)GoButton_Callback(hObject, eventdata, handles),'StartDelay',15);
In the first function I call (GoButton_Callback), which is then the function to initialize another trial as well, I stop the timer:
%stop the timer
stop(handles.gotimer)
guidata(hObject,handles);
That function then calls one of my playback functions, at the end of which I run the timer and go back to the GoButton:
if rep_num < 65;
start(handles.gotimer);
guidata(hObject,handles);
end
At this point, the GoButton function goes to stop the timer (see above), and I get an error:
??? Error while evaluating TimerFcn for timer 'timer-7'
Reference to non-existent field 'gotimer'.
I should note that the number of the timer does seem to be creeping up, so I'm wondering if I keep creating another timer object. Anyone have ideas?

답변 (1개)

Sean de Wolski
Sean de Wolski 2012년 7월 16일
As for the timers incrementing count. This will happen. Make sur eyou delete your timers when you are done with them!
t = timerfind;
or
t = timerfindall;
And:
if ~isempty(t)
stop(t)
delete(t);
end

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by