Monitoring Progress in Matlab

There are a lot of pre-made codes out there to make progress bars for your code.  A lot of these work fine, but some will slow down your code.  The last thing you want is a progress bar that hampers progress. I like the built-in waitbar function in matlab.  It's pretty easy to use following the help dialog, with the caveat that it doesn't play well with parfor loops.  You can write a quick script to monitor the progress of your code.

Screen Shot 2013-02-15 at 4.54.03 PM

First, before the for loop initialize the progressbar:

Length=n;
Count=0;
WaitBar = waitbar(0,'Initializing waitbar...');
tic;

tic; starts the timer that you'll use to estimate the remaning time.

for i=1:n
  do stuff

   %Here's the progress bar code
   t=toc;
   Perc=Count/Length;
   Trem=t/Perc-t; %Calculate the time remaining
   Hrs=floor(Trem/3600);Min=floor((Trem-Hrs*3600)/60);
   waitbar(Perc,Handle,[sprintf('%0.1f',Perc*100) '\%, '...
     sprintf('%03.0f',Hrs) ':'...
     sprintf('%02.0f',Min) ':'...
     sprintf('%02.0f',rem(Trem,60)) ' remaining']);
end

 

For parfor loops i'm working on a solution that has low overhead, and gives an overall sense for progress. The idea uses the tic and toc commands in Matlab, and operates under the assumption that each iteration of parfor takes roughly the same amount of time.  the idea then uses two counters - one tracking the total time the loop has been operating, and one counting the time each current operation uses.  An estimate for Count can be obtained by dividing the too, although when I tested, Matlab came up with display warnings trying to display the bar...

Related Posts:

This entry was posted in Uncategorized and tagged , , , , , . Bookmark the permalink.