How to run a for loop every one second ?

조회 수: 6 (최근 30일)
Arun Badigannavar
Arun Badigannavar 2013년 5월 9일
댓글: sharad kamble 2016년 10월 7일
In M Script how to execute a for loop every one second?
  댓글 수: 3
Arun Badigannavar
Arun Badigannavar 2013년 5월 10일
ya but i am unable to do it without pause command
sharad kamble
sharad kamble 2016년 10월 7일
Thank you for the solution. .

댓글을 달려면 로그인하십시오.

채택된 답변

Friedrich
Friedrich 2013년 5월 10일
편집: Friedrich 2013년 5월 10일
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.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Database Toolbox에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by