using callback function in timer with a function generated within script
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Quentin
le 24 Fév 2014
Réponse apportée : Quentin
le 25 Fév 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 commentaire
Réponse acceptée
per isakson
le 25 Fév 2014
Modifié(e) : per isakson
le 25 Fév 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 commentaires
Plus de réponses (1)
Voir également
Catégories
En savoir plus sur Dialog Boxes dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!