using callback function in timer with a function generated within script
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Quentin
el 24 de Feb. de 2014
Respondida: Quentin
el 25 de Feb. de 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 comentario
Respuesta aceptada
per isakson
el 25 de Feb. de 2014
Editada: per isakson
el 25 de Feb. de 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 comentarios
Más respuestas (1)
Ver también
Categorías
Más información sobre Dialog Boxes en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!