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

4 views (last 30 days)
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?

Accepted Answer

Walter Roberson
Walter Roberson on 27 Aug 2018
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 Comments
Leon
Leon on 27 Aug 2018
Many thanks! I wonder how much extra resource the if loop will consume?
Walter Roberson
Walter Roberson on 28 Aug 2018
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.

Sign in to comment.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Tags

Products


Release

R2018a

Community Treasure Hunt

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

Start Hunting!