TimerFcn in gui from one function to another

1 次查看(过去 30 天)
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