How can I show how much time is left for a script to complete?
이전 댓글 표시
I know there's a function call 'waitbar'; however, I want to show whoever is running my script how much time is left before it will be finished. It is a long script that consists of many different functions and loops.
Thanks, Mirage
댓글 수: 3
David Barry
2012년 11월 6일
편집: David Barry
2012년 11월 6일
Are you looking to display a time in seconds or percentage complete? This problem is highly dependent on your code so it's tricky to give a precise answer. Typically you would put the waitbar inside the loop, for example:
h = waitbar(0,'Please wait...');
steps = 1000;
for step = 1:steps
% computations take place here
waitbar(step / steps)
end
close(h)
If you wanted to display a time then you would have to time the first iteration of the loop using tic toc and then update accordingly. Of course this all depends on your code. Could you include an example of your code?
Mirage
2012년 11월 7일
Paulo Abelha
2016년 9월 17일
Hi Dave,
I've coded a function that might help you:
https://uk.mathworks.com/matlabcentral/fileexchange/59187-displayestimatedtimeofloop--tot-toc--curr-ix--tot-iter--
답변 (2개)
Chad Greene
2012년 11월 6일
Clever use of tic and toc may provide an estimate of how much time the script has been running, and how much time is left.
tic
steps = 10;
for step = 1:steps
% [calculations here]
if step==1
toc1=toc;
end
time_elapsed = toc;
estimated_time_remaining = (steps-step)*toc1;
disp([num2str(time_elapsed),' seconds down, ',num2str(estimated_time_remaining),' seconds to go!'])
end
John Petersen
2012년 11월 6일
0 개 추천
One thing you can do is determine where the bulk of the computation time resides. Hopefully this is in a loop. You could then time each loop and then display the time left based on how many iterations remain. Otherwise, it's going to vary too much from computer to computer to be very useful.
카테고리
도움말 센터 및 File Exchange에서 App Building에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!