Need help computing average time for a code I made
1 view (last 30 days)
Show older comments
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 Comments
Answers (1)
Star Strider
on 6 Nov 2017
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 Comments
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!