I would like to set up a counter that informs me about a long iterative computation (e.g. in for
).
Is it possible to set up this counter in a way that when it is updated on screen, it replaces the previous value?
That is, printing the iterator variable of a for
is not ok, since Matlab either prints it into a new line, or after the previous value, but after 10000 iterations the screen would be filled either way. Also, I would like to update the counter in each turn.
fprintf('\n')
for i=1:15
fprintf([repmat('\b', 1, length(num2str(i-1))) '%d'], i)
pause(0.1)
end
fprintf('\n')
You can use \b
to print a backspace character. e.g.:
for i=1:10
fprintf(1, '\b%d', i);
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With