Need help computing average time for a code I made
조회 수: 1 (최근 30일)
이전 댓글 표시
My professor wants me to generate a loop that will run my code 10 times. For those 10 times he wants me to compute the time for each loop and find the average time. So I am supposed to get ten values for the time(t) and divide that value by 10 to get the average time it takes to run the program. My classmates and me have come to the conclusion that the loop (see code on bottom) we made should give us the average time but we are not sure. The last line should print out the final answer for the loop.
for i = 1:10
tic
someCode
t(i) = toc
end
disp(sum(t)/10)
댓글 수: 0
답변 (1개)
Star Strider
2017년 11월 6일
That should work. You can also use the mean function:
for i = 1:10
tic
someCode
t(i) = toc;
end
disp(sum(t)/10)
disp(mean(t))
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!