Effacer les filtres
Effacer les filtres

using callback function in timer with a function generated within script

1 vue (au cours des 30 derniers jours)
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

Réponse acceptée

per isakson
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

Plus de réponses (1)

Quentin
Quentin le 25 Fév 2014
Thank you for the help. Once I put it into one code and saw it work, I realized the problem was most likely in the gui. I'm trouble shooting the gui now but your input helped me locate the troublesome code.
Thanks again, Quentin

Catégories

En savoir plus sur Get Started with MATLAB 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!

Translated by