# Displaying the Progress of a Long Running MATLAB Script, Part 1: fprintf3

Posted by Stuart McGarrity,

I have a number of scripts that take several hours to run and I like be able to track their progress. I use a few techniques to do this, including this first example, which just uses fprintf. (Remember you can switch the video player to full screen to make it more readable)

## 3 CommentsOldest to Newest

Sean de Wolski replied on : 1 of 3
I like to use '\b' in "fprintf" to keep the iteration updates in one place rather than chewing through the command window.
n = 1000;

fprintf(1,'Processing %04i, of %i\n',0,n);
for ii = 1:n
fprintf(1,'\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b %04i, of %i\n',ii,n);
pause(0.01)
end

Stuart McGarrity replied on : 2 of 3
Yes, that is a useful technique.
Julian replied on : 3 of 3
While I have been using techniques such as you describe for many years it was useful to learn that I can use fprintf without a file identifier to send output to the screen! I have always used fprintf(1, ...) to send to stdout and fprintf(2, ...) to send to stderr. I never noticed this new feature when it was introduced... I guess it explains all those mlint messages "This call of fprintf will produce output that will be printed", which always had me scratching my head.

This site uses Akismet to reduce spam. Learn how your comment data is processed.