<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Monitoring Progress of a Calculation</title>
	<atom:link href="http://blogs.mathworks.com/loren/2007/08/01/monitoring-progress-of-a-calculation/feed/" rel="self" type="application/rss+xml" />
	<link>http://blogs.mathworks.com/loren/2007/08/01/monitoring-progress-of-a-calculation/</link>
	<description>Loren Shure works on design of the MATLAB language at MathWorks. She writes here about once a week on MATLAB programming and related topics.</description>
	<lastBuildDate>Mon, 13 Feb 2012 13:24:10 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: Andrew</title>
		<link>http://blogs.mathworks.com/loren/2007/08/01/monitoring-progress-of-a-calculation/#comment-32866</link>
		<dc:creator>Andrew</dc:creator>
		<pubDate>Sun, 01 Jan 2012 23:16:22 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2007/08/01/monitoring-progress-of-a-calculation/#comment-32866</guid>
		<description>I just came across this page and wrote my own little version that&#039;s a bit like jkarretero&#039;s example but without a double FOR loop using a compact implementation of repmat():


m = 1e3;
bs = &#039;\b&#039;;
sp = &#039; &#039;;
msg = &#039;%d iterations...\n&#039;; % carriage return included in case error interrupts loop
msglen = length(msg)-3;  % compensate for conversion character and carriage return
fprintf(1,sp(ones(1,ceil(log10(m+1))+msglen)));
for i=1:m
    fprintf(1,[bs(mod(0:2*(ceil(log10(i+1))+msglen)-1,2)+1) msg],i);
    pause(0.01);
end


This can be modified a bit if you don&#039;t want the progress digit at the beginning:


m = 1e3;
bs = &#039;\b&#039;;
sp = &#039; &#039;;
msg = &#039;Iteration %d...\n&#039;;  % carriage return included in case error interrupts loop
msglen = length(msg)-3; % compensate for conversion character and carriage return
fprintf(1,sp(ones(1,msglen)));
for i=1:m
    fprintf(1,[bs(mod(0:2*(ceil(log10(i))+msglen)-1,2)+1) msg],i);
    pause(0.01);
end


Note that it&#039;s a good idea to include a carriage return at the end of your message because any error message from a loop whose progress you&#039;re monitoring doesn&#039;t start with a new line.

Also, maybe it&#039;s obvious, but as long as the code whose progress you&#039;re monitoring takes a nominal amount of time to execute, don&#039;t forget to remove any pause() statements from your loop. All they do is slow it down and I haven&#039;t seen any problems with the command window not updating. ...Except... I have however seen what looks like a race condition when the schemes above are called in a sufficiently tight loop and the first character or two don&#039;t get written (R2011b, Mac OS X 10.6.8). It&#039;s most noticeable when the loop increment is a power of ten. The non-updating of those characters in the command window persists even after the code has finished executing.</description>
		<content:encoded><![CDATA[<p>I just came across this page and wrote my own little version that&#8217;s a bit like jkarretero&#8217;s example but without a double FOR loop using a compact implementation of repmat():</p>
<p>m = 1e3;<br />
bs = &#8216;\b&#8217;;<br />
sp = &#8216; &#8216;;<br />
msg = &#8216;%d iterations&#8230;\n&#8217;; % carriage return included in case error interrupts loop<br />
msglen = length(msg)-3;  % compensate for conversion character and carriage return<br />
fprintf(1,sp(ones(1,ceil(log10(m+1))+msglen)));<br />
for i=1:m<br />
    fprintf(1,[bs(mod(0:2*(ceil(log10(i+1))+msglen)-1,2)+1) msg],i);<br />
    pause(0.01);<br />
end</p>
<p>This can be modified a bit if you don&#8217;t want the progress digit at the beginning:</p>
<p>m = 1e3;<br />
bs = &#8216;\b&#8217;;<br />
sp = &#8216; &#8216;;<br />
msg = &#8216;Iteration %d&#8230;\n&#8217;;  % carriage return included in case error interrupts loop<br />
msglen = length(msg)-3; % compensate for conversion character and carriage return<br />
fprintf(1,sp(ones(1,msglen)));<br />
for i=1:m<br />
    fprintf(1,[bs(mod(0:2*(ceil(log10(i))+msglen)-1,2)+1) msg],i);<br />
    pause(0.01);<br />
end</p>
<p>Note that it&#8217;s a good idea to include a carriage return at the end of your message because any error message from a loop whose progress you&#8217;re monitoring doesn&#8217;t start with a new line.</p>
<p>Also, maybe it&#8217;s obvious, but as long as the code whose progress you&#8217;re monitoring takes a nominal amount of time to execute, don&#8217;t forget to remove any pause() statements from your loop. All they do is slow it down and I haven&#8217;t seen any problems with the command window not updating. &#8230;Except&#8230; I have however seen what looks like a race condition when the schemes above are called in a sufficiently tight loop and the first character or two don&#8217;t get written (R2011b, Mac OS X 10.6.8). It&#8217;s most noticeable when the loop increment is a power of ten. The non-updating of those characters in the command window persists even after the code has finished executing.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Loren</title>
		<link>http://blogs.mathworks.com/loren/2007/08/01/monitoring-progress-of-a-calculation/#comment-32656</link>
		<dc:creator>Loren</dc:creator>
		<pubDate>Tue, 15 Nov 2011 15:54:23 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2007/08/01/monitoring-progress-of-a-calculation/#comment-32656</guid>
		<description>inwoo yoon,

Can you please tell us exactly what version of MATLAB you are running on PC and linux?  Thanks.

--Loren</description>
		<content:encoded><![CDATA[<p>inwoo yoon,</p>
<p>Can you please tell us exactly what version of MATLAB you are running on PC and linux?  Thanks.</p>
<p>&#8211;Loren</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: inwoo yoon</title>
		<link>http://blogs.mathworks.com/loren/2007/08/01/monitoring-progress-of-a-calculation/#comment-32620</link>
		<dc:creator>inwoo yoon</dc:creator>
		<pubDate>Thu, 10 Nov 2011 16:44:20 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2007/08/01/monitoring-progress-of-a-calculation/#comment-32620</guid>
		<description>Regarding backspace, I noticed that when multiple backspace is printed, Linux version will stop at the beginning of the line and PC version will go past the beginning of the line and to the previous line. Is that how it&#039;s supposed to work?</description>
		<content:encoded><![CDATA[<p>Regarding backspace, I noticed that when multiple backspace is printed, Linux version will stop at the beginning of the line and PC version will go past the beginning of the line and to the previous line. Is that how it&#8217;s supposed to work?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ariel Balter</title>
		<link>http://blogs.mathworks.com/loren/2007/08/01/monitoring-progress-of-a-calculation/#comment-32412</link>
		<dc:creator>Ariel Balter</dc:creator>
		<pubDate>Thu, 04 Aug 2011 19:19:07 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2007/08/01/monitoring-progress-of-a-calculation/#comment-32412</guid>
		<description>disp is much faster I compared the code by yast 

http://blogs.mathworks.com/loren/2007/08/01/monitoring-progress-of-a-calculation/#comment-16357

to the following:

&lt;pre&gt;
tic;
for i = 1:1000000;
   if (mod(i,1000) == 0);
      disp(i/1000000)
   end
end
toc
&lt;/pre&gt;

and I found the latter 10x faster than the fastest waitbar.</description>
		<content:encoded><![CDATA[<p>disp is much faster I compared the code by yast </p>
<p><a href="http://blogs.mathworks.com/loren/2007/08/01/monitoring-progress-of-a-calculation/#comment-16357" rel="nofollow">http://blogs.mathworks.com/loren/2007/08/01/monitoring-progress-of-a-calculation/#comment-16357</a></p>
<p>to the following:</p>
<pre>
tic;
for i = 1:1000000;
   if (mod(i,1000) == 0);
      disp(i/1000000)
   end
end
toc
</pre>
<p>and I found the latter 10x faster than the fastest waitbar.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Loren</title>
		<link>http://blogs.mathworks.com/loren/2007/08/01/monitoring-progress-of-a-calculation/#comment-32315</link>
		<dc:creator>Loren</dc:creator>
		<pubDate>Mon, 13 Jun 2011 10:09:18 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2007/08/01/monitoring-progress-of-a-calculation/#comment-32315</guid>
		<description>Kamil- Thanks.

Gianluca-  I don&#039;t know. But I think you need to start WITH the desktop instead of -nodesktop.  That&#039;s just a guess based on the warnings.  Otherwise, I suggest you contact technical support (link on right of the blog).

--Loren</description>
		<content:encoded><![CDATA[<p>Kamil- Thanks.</p>
<p>Gianluca-  I don&#8217;t know. But I think you need to start WITH the desktop instead of -nodesktop.  That&#8217;s just a guess based on the warnings.  Otherwise, I suggest you contact technical support (link on right of the blog).</p>
<p>&#8211;Loren</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kamil</title>
		<link>http://blogs.mathworks.com/loren/2007/08/01/monitoring-progress-of-a-calculation/#comment-32314</link>
		<dc:creator>Kamil</dc:creator>
		<pubDate>Sat, 11 Jun 2011 00:17:26 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2007/08/01/monitoring-progress-of-a-calculation/#comment-32314</guid>
		<description>Another example:
&lt;pre&gt;
    progress.text = sprintf( &#039;Completed: %%3.0f%%%%%%s&#039; );
    progress.clear = sprintf( &#039;%s&#039;, ...
        sprintf(&#039;\b&#039;)*ones(1,length(sprintf(progress.text,0,&#039;&#039;))) );
    N = 100+400*rand();
    for n = 0:N
        fprintf( progress.text, n/N*100, progress.clear );
        pause( 0.01 );
    end
    fprintf( progress.text, n/N*100, sprintf(&#039;\n&#039;) ); 
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>Another example:</p>
<pre>
    progress.text = sprintf( 'Completed: %%3.0f%%%%%%s' );
    progress.clear = sprintf( '%s', ...
        sprintf('\b')*ones(1,length(sprintf(progress.text,0,''))) );
    N = 100+400*rand();
    for n = 0:N
        fprintf( progress.text, n/N*100, progress.clear );
        pause( 0.01 );
    end
    fprintf( progress.text, n/N*100, sprintf('\n') );
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gianluca</title>
		<link>http://blogs.mathworks.com/loren/2007/08/01/monitoring-progress-of-a-calculation/#comment-32313</link>
		<dc:creator>Gianluca</dc:creator>
		<pubDate>Fri, 10 Jun 2011 22:29:02 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2007/08/01/monitoring-progress-of-a-calculation/#comment-32313</guid>
		<description>I&#039;d like to know if there is any way to use the waitbar in a parallelised code (i.e. matlabpool, spmd). I tried that and I keep getting this error..
Warning: This functionality is no longer supported under the -nodisplay and
  -noFigureWindows startup options. For more information, see &quot;Changes to
  -nodisplay and -noFigureWindows Startup Options&quot; in the MATLAB Release Notes.
  To view the release note in your system browser, run
  web(&#039;http://www.mathworks.com/access/helpdesk/help/techdoc/rn/br5ktrh-1.html#br5ktrh-3&#039;,
  &#039;-browser&#039;) 
  &gt; In uitools\private\warnfiguredialog at 19
    In waitbar at 39
    In remoteBlockExecution at 48

Do you know what the reason is?
Cheers
Gianluca</description>
		<content:encoded><![CDATA[<p>I&#8217;d like to know if there is any way to use the waitbar in a parallelised code (i.e. matlabpool, spmd). I tried that and I keep getting this error..<br />
Warning: This functionality is no longer supported under the -nodisplay and<br />
  -noFigureWindows startup options. For more information, see &#8220;Changes to<br />
  -nodisplay and -noFigureWindows Startup Options&#8221; in the MATLAB Release Notes.<br />
  To view the release note in your system browser, run<br />
  web(&#8216;<a href="http://www.mathworks.com/access/helpdesk/help/techdoc/rn/br5ktrh-1.html#br5ktrh-3&#039;" rel="nofollow">http://www.mathworks.com/access/helpdesk/help/techdoc/rn/br5ktrh-1.html#br5ktrh-3&#039;</a>,<br />
  &#8216;-browser&#8217;)<br />
  &gt; In uitools\private\warnfiguredialog at 19<br />
    In waitbar at 39<br />
    In remoteBlockExecution at 48</p>
<p>Do you know what the reason is?<br />
Cheers<br />
Gianluca</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Loren</title>
		<link>http://blogs.mathworks.com/loren/2007/08/01/monitoring-progress-of-a-calculation/#comment-32119</link>
		<dc:creator>Loren</dc:creator>
		<pubDate>Mon, 14 Mar 2011 22:37:30 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2007/08/01/monitoring-progress-of-a-calculation/#comment-32119</guid>
		<description>Julia-

You CAN but it&#039;s not necessarily a good idea.  A better idea is to write myfprintf and call that.  Put your extra code in there and then call myfprintf.  Otherwise, the version of fprintf will have your modifications even for applications that aren&#039;t expecting it - perhaps code from other people that you have downloaded, etc.

To change fprintf, you need to find a directory on your path in which to create a subdirectory called @char NOT on your path.  Inside that @char directory, create the version of fprintf that you want, and then, use the builtin function to call the version of fprintf from MATLAB from your own.  Again, I REALLY DISCOURAGE you for doing this!  The different name scenario is much safer.

--Loren</description>
		<content:encoded><![CDATA[<p>Julia-</p>
<p>You CAN but it&#8217;s not necessarily a good idea.  A better idea is to write myfprintf and call that.  Put your extra code in there and then call myfprintf.  Otherwise, the version of fprintf will have your modifications even for applications that aren&#8217;t expecting it &#8211; perhaps code from other people that you have downloaded, etc.</p>
<p>To change fprintf, you need to find a directory on your path in which to create a subdirectory called @char NOT on your path.  Inside that @char directory, create the version of fprintf that you want, and then, use the builtin function to call the version of fprintf from MATLAB from your own.  Again, I REALLY DISCOURAGE you for doing this!  The different name scenario is much safer.</p>
<p>&#8211;Loren</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Julia</title>
		<link>http://blogs.mathworks.com/loren/2007/08/01/monitoring-progress-of-a-calculation/#comment-32118</link>
		<dc:creator>Julia</dc:creator>
		<pubDate>Mon, 14 Mar 2011 21:20:33 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2007/08/01/monitoring-progress-of-a-calculation/#comment-32118</guid>
		<description>I&#039;d like to know if there is any way to overwrite fprintf built-in function? I wan to add some my own action in fprintf function before I call the built-in fprintf. 
I know how to overwrite disp, but I do not know how to overwrite fprintf. I&#039;d like to know if it is possible. Could you please help? Thanks.</description>
		<content:encoded><![CDATA[<p>I&#8217;d like to know if there is any way to overwrite fprintf built-in function? I wan to add some my own action in fprintf function before I call the built-in fprintf.<br />
I know how to overwrite disp, but I do not know how to overwrite fprintf. I&#8217;d like to know if it is possible. Could you please help? Thanks.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Loren</title>
		<link>http://blogs.mathworks.com/loren/2007/08/01/monitoring-progress-of-a-calculation/#comment-31253</link>
		<dc:creator>Loren</dc:creator>
		<pubDate>Wed, 07 Apr 2010 12:47:33 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2007/08/01/monitoring-progress-of-a-calculation/#comment-31253</guid>
		<description>Abe-

Good suggestion.  Please use the support link at the right to make the request (it counts more if it comes from you than if it comes from me).

--Loren</description>
		<content:encoded><![CDATA[<p>Abe-</p>
<p>Good suggestion.  Please use the support link at the right to make the request (it counts more if it comes from you than if it comes from me).</p>
<p>&#8211;Loren</p>
]]></content:encoded>
	</item>
</channel>
</rss>

