How to run a for loop every one second ?

12 vues (au cours des 30 derniers jours)
Arun Badigannavar
Arun Badigannavar le 9 Mai 2013
Commenté : sharad kamble le 7 Oct 2016
In M Script how to execute a for loop every one second?
  3 commentaires
Arun Badigannavar
Arun Badigannavar le 10 Mai 2013
ya but i am unable to do it without pause command
sharad kamble
sharad kamble le 7 Oct 2016
Thank you for the solution. .

Connectez-vous pour commenter.

Réponse acceptée

Friedrich
Friedrich le 10 Mai 2013
Modifié(e) : Friedrich le 10 Mai 2013
Try this,
function a = test
a = timer('ExecutionMode','fixedRate','Period',1,'TimerFcn',@myfun);
start(a);
end
function myfun(obj,evt)
for i=1:3
disp(datestr(now));
end
disp('===============');
end
and call it with
my_timer = test();
When you like to stop the timer call
stop(my_timer)
Or in the case you want to wait until the timer is done and you know how often the for loop should be triggered do this:
function a = test
a = timer('ExecutionMode','fixedRate','Period',1,'TimerFcn',@myfun,'TasksToExecute',10);
start(a);
wait(a);
disp('timer done')
end
function myfun(obj,evt)
for i=1:3
disp(datestr(now));
end
disp('===============');
end
Make sure the tme myfun needs to run is lower than 1 second.

Plus de réponses (0)

Tags

Aucun tag saisi pour le moment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by