using callback function in timer with a function generated within script
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Quentin
am 24 Feb. 2014
Beantwortet: Quentin
am 25 Feb. 2014
Hi all,
I think I have a reasonably straightforward question. I am trying to use a timer function in matlab but I am getting a consistent error. I have generated a gui and I want it to execute a function periodically when a button is pressed. The troublesome part of the code looks like this
acquisitionTimer = timer;
acquisitionTimer.ExecutionMode = 'fixedRate';
acquisitionTimer.TasksToExecute = sweepsPerTrigger;
acquisitionTimer.Period = inter_stimulus_interval;
acquisitionTimer.StopFcn = @acquisitionTimerCleanup;
acquisitionTimer.TimerFcn = @(myTimerObj, thisEvent)startAcquisition;
start(acquisitionTimer);
function acquisitionTimerCleanup(acquisitionTimer,~)
disp('Done Acquiring');
delete(acquisitionTimer)
function startAcquisition
(this starts my aquisition code)
--- So I think my problem is with the callback function line
acquisitionTimer.TimerFcn = @(myTimerObj, thisEvent)startAcquisition;
I get the impression this is not how you start a function when linking it with a timer. Any advice would be greatly appreciated. I looked at the documention, but unfortunately, I can't seem to figure it out right now.
Thanks, Quentin
1 Kommentar
Akzeptierte Antwort
per isakson
am 25 Feb. 2014
Bearbeitet: per isakson
am 25 Feb. 2014
I put your code into one m-file and it worked. I cannot see any problem. With R2013a
>> cssm
start Acquisition
start Acquisition
Done Acquiring
>>
where cssm is
function cssm
acquisitionTimer = timer;
acquisitionTimer.ExecutionMode = 'fixedRate';
acquisitionTimer.TasksToExecute = 2;
acquisitionTimer.Period = 1;
acquisitionTimer.StopFcn = @acquisitionTimerCleanup;
acquisitionTimer.TimerFcn = @(myTimerObj, thisEvent)startAcquisition;
start(acquisitionTimer);
end
function acquisitionTimerCleanup(acquisitionTimer,~)
disp('Done Acquiring');
delete(acquisitionTimer)
end
function startAcquisition
% (this starts my aquisition code)
disp('start Acquisition')
end
0 Kommentare
Weitere Antworten (1)
Siehe auch
Kategorien
Mehr zu Dialog Boxes finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!