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

7 次查看(过去 30 天)
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