Progress/percent complete bar

조회 수: 453 (최근 30일)
Anthony
Anthony 2015년 7월 24일
댓글: John 2022년 12월 3일
So my question/problem is that I am trying to make a window appear that states the estimated completion time of my code, the total time the code has been running, and the percent complete the code is. I tried to use the waitbar and progress bar functions but they both run using a for loop with many iterations. I can't use these functions because my code takes approximately 3 hours to run and to run a certain amount iterations of a 3 hour code would take days. So does anyone have any advice on how to have some sort of window appear that updates the specified wants seen above as my code proceeds to run?
  댓글 수: 2
Jan
Jan 2015년 7월 24일
I do not understand the question. What is the problem with waitbar? What does "They run using a for loop with many iterations" mean? I do not see, why you cannot use waitbar, when your code needs 3 hours. What is the actual problem? That waitbar is too small to show the progress?
John
John 2022년 12월 3일
I know this isn't what you wanted, but I occasionally add a breakpoint to pause the program, look at the iteration variable (ex for i = 1:n, i would peek at i's value in the variables section), do some mental math comparing i to n, remove the breakpoint, and press continue. In python there are some good answers, but with my code in matlab, I don't trust myself to interact with I/O without tanking the efficency, so this is my bandaid solution.

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

답변 (2개)

bio lim
bio lim 2015년 7월 24일
편집: bio lim 2015년 7월 24일
Take a look at the waitbar(). It displays a figure that shows what percentage of a calculation is complete. Also take a look at Code Performance in the documentation. Moreover take a look at these two. ( 1 and 2 )
Also there is a progressbar file on the File Exchange.
  댓글 수: 4
Ali Yar Khan
Ali Yar Khan 2019년 12월 18일
can anyone answer this question please https://www.mathworks.com/matlabcentral/answers/497176-show-the-progress-of-fitecoc-classifier
Mike Shives
Mike Shives 2020년 12월 7일
There is quite a bit of overhead in updating the waitbar, so it's good to use mod to alter the update rate, e.g. if Nt is the total number of i you expect to run in your loop...
hw = waitbar(0,'Running...');
for i = 1:Nt
%% code here that does things...
if mod(i,floor(Nt/10))<1e-2
waitbar(i/Nt,hw);
end
end

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


Hesham Ismail
Hesham Ismail 2015년 7월 24일
Hello,
Let say you have a loop that runs for 3 hours
for i = 1: 3 hours
i
end
if i is the first hour window then you can have at the end of your code something like this
for i = 1: 3
if i==1
display('33.3percentage completed')
elseif i==2
display('66.7percentage completed')
else
display('100percentage completed')
end
end
  댓글 수: 1
Anthony
Anthony 2015년 7월 24일
But what I am looking for is a window that appears and updates as time goes on because depending on the data I am running with my code it may take 1 hour, 2 hours, or 3 hours. The point is I do not know how long it will take to run and the user needs to see a message or window displaying estimated time until completion, time running and percent complete.

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

카테고리

Help CenterFile Exchange에서 Dialog Boxes에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by