can anyone help me to sort out the problem here

조회 수: 1 (최근 30일)
rem ng
rem ng 2019년 2월 3일
댓글: rem ng 2019년 2월 4일
In this Ex. i want all the functions under r loop to run for each r iteration (taken one at a time till rmax) with specific execution time not the iteration time for the whole r loop. I mean say r=3, if all operation under iteration r=3 should run for 0.5sec then how should i o for it. Thanks in advance.
Ex: rmax=1000
n=100
for r=0:1:rmax
(some operation)
for i=1:1:n
(some operation)
if (some condition)
end
end
end
  댓글 수: 2
KALYAN ACHARJYA
KALYAN ACHARJYA 2019년 2월 3일
Sorry the questions is not clear for me.
rem ng
rem ng 2019년 2월 3일
@kalyan I want to make the execution time (round time in my program) of each r iteration value according to my desire seconds so that the operation under r loop can be operated for that round time only for each r iteration.
say ex: if r=2 the execution time is 0.24 sec to perform the operation under this loop. is there any option to change the exceution time of each r?

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

채택된 답변

Walter Roberson
Walter Roberson 2019년 2월 3일
TT = tic;
while toc(TT) < timelimit
do more of the calculation
end
  댓글 수: 4
Walter Roberson
Walter Roberson 2019년 2월 3일
It depends on how accurate you need the timing to be. If you have
TT = tic;
while toc(TT) < timelimit
for K = 1 : r
do more of the calculation
end
end
then the time spent in the for loop would be r times how long it takes to do each iteration, and that would determine how often toc was checked. Typically larger r would be more efficient but would lead to toc being checked less often.
rem ng
rem ng 2019년 2월 4일
@walter thanks a load Sir. Your information really helps a lot.

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

추가 답변 (1개)

KALYAN ACHARJYA
KALYAN ACHARJYA 2019년 2월 3일
편집: KALYAN ACHARJYA 2019년 2월 3일
If you want to change the execution time for the iterations, you can look for indexing (avoid loop if possible) or use the functions and call in the current scripts.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by