Be the first to rate this file! 17 Downloads (last 30 days) File Size: 93.8 KB File ID: #35074
image thumbnail

Display progress, pause or stop a time-consuming loop

by

 

14 Feb 2012 (Updated )

Allows you to display a loop’s progress, pause (and also change related code) or stop it.

Editor's Notes:

This file was selected as MATLAB Central Pick of the Week

| Watch this File

File Information
Description

This class creates a small pause/stop window, that allows you to either abort a running loop or pause the execution and create breakpoints or change/correct mistakes in the code (this works for files that are not in the stack from where stop.requested is called).

It can be used in different ways:
- Control the loop execution:
  while ~stop.requested
     %do your heavy calculations here
  end
  stop.close;

- abort execution in the middle
  for i = 1:100
     %do your heavy calculations here
     if stop.requested
        stop.close;
        error('Stop requested')
     end
  end

- inform the current progress
  iter = 1;
  maxIter = 1000;

  while iter<maxIter || stop.requested
     %do your heavy calculations here
     progress = iter/maxIter;
     stop.setStatus('Running...',progress);
  end
  stop.close;

In loops with many iterations, you can also avoid updating the screen too often (and reduce the impact of calling stop.request), by calling: stop.requested(num); where num is the interval on which the gui will be refreshed to check for user interaction.

And to enable the easter egg (xkcd.com/1017/), use:
stop.setStatus('xkcd', progress);

Required Products MATLAB
MATLAB release MATLAB 7.13 (R2011b)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (1)
12 Dec 2013 kasim tasdemir

Hi,

I use 'dispstat' function just for this purpose. It can update the previous output which is a missing function of default 'disp'. Very simple to use. It can be downloaded from here:

http://www.mathworks.com/matlabcentral/fileexchange/44673

***Sample usage:
dispstat('','init'); % One time only initialization
dispstat(sprintf('Begining the process...'),'keepthis','timestamp');
for i = 97:100
dispstat(sprintf('Progress %d%%',i),'timestamp');
%doing some heavy stuff here
end
dispstat('Finished.','keepprev');

***Output:
11:25:37 Begining the process...
11:25:37 Progress 100%
Finished.

All the best

Updates
14 Feb 2012

14/02/2012 - Corrected the stop.close behavior

17 Feb 2012

Added easter egg: xkcd.com/1017/

Contact us