In M Script how to execute a for loop every one second?

댓글 수: 3

Did you consider to use the timer?
doc timer
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일

2 개 추천

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개)

카테고리

도움말 센터File Exchange에서 Profile and Improve Performance에 대해 자세히 알아보기

태그

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

질문:

2013년 5월 9일

댓글:

2016년 10월 7일

Community Treasure Hunt

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

Start Hunting!

Translated by