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

3 visualizzazioni (ultimi 30 giorni)
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?

Risposta accettata

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

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Tag

Prodotti


Release

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by