How to show the progress of a program without using disp()?

조회 수: 7 (최근 30일)
Leon
Leon 2018년 8월 27일
댓글: Walter Roberson 2018년 8월 28일
Recently, I've been running several large programs that would take many days to finish. It's very important for me to know the progress of the program, so that I know it is not stuck somewhere.
What is the best way to show the progress? I tried to use disp(i), but it obviously slows down the program. Is there a better way to achieve this?

채택된 답변

Walter Roberson
Walter Roberson 2018년 8월 27일
waitbar() is a common way to show progress.
However, remember that waitbar() uses resources too, so using disp() selectively can be more efficient. For example instead of disp(i) you might have
if mod(i, 50) == 0; disp(i); end
or
if mod(i, 10) == 0; fprintf('.'); end; if mod(i, 500) == 0; fprintf('\n'); end
  댓글 수: 2
Leon
Leon 2018년 8월 27일
Many thanks! I wonder how much extra resource the if loop will consume?
Walter Roberson
Walter Roberson 2018년 8월 28일
mod() is not the fastest operation, but it is not bad.
My tests show that it is possible to do slightly better if you are willing to test at powers of 2 instead of using decimal:
mod(A_Double, A_Double)
is just slightly slower than
bitand(A_uint16, A_uint16)
for example,
u63 = uint16(63);
for K = uint16(1:30000)
...
if ~bitand(K, u63) ...
end
end
would be true at multiples of 64.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

태그

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by