Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to monitor long calculations?

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.

like image 850
István Zachar Avatar asked Feb 19 '12 19:02

István Zachar


2 Answers

fprintf('\n')
for i=1:15
    fprintf([repmat('\b', 1, length(num2str(i-1))) '%d'], i)
    pause(0.1)
end
fprintf('\n')
like image 110
Simon Avatar answered Nov 01 '22 12:11

Simon


You can use \b to print a backspace character. e.g.:

for i=1:10
    fprintf(1, '\b%d', i);
end
like image 39
Oliver Charlesworth Avatar answered Nov 01 '22 13:11

Oliver Charlesworth