Code covered by the BSD License  

Highlights from
progressbar

4.41667

4.4 | 12 ratings Rate this file 50 Downloads (last 30 days) File Size: 5.45 KB File ID: #3607
image thumbnail

progressbar

by Ohad Gal

 

17 Jun 2003 (Updated 18 Jun 2003)

Progressbar with an abort button.

| Watch this File

File Information
Description

This zip file contain 3 files:
    progressbar.m - the progress bar
    gui_active.m - polling function to be used in the runnig application (optional)
    gauge_abort_icon.mat - the icon on the button (optional button)

Directions:
    place 3 files in the same folder, and let MATLAB "know" it's path.
    you can create as many progressbars as you want,
    and update each of them using a unique handle.

    if a progress bar is closed using the "X" button on the upper-right
    corner of the progressbar, the function will create it again
    with it's same state, see example below (use copy-paste)
    
% progressbar - shows a progress bar dialog based on the function "waitbar"
%
% Format: handle = progressbar( handle,increment [,string,titlestr] )
%
% Input: handle - handle to current progress bar, [] for a new one
% increment - a fraction (0..1) to increment by.
% (-1) signals the function to remove the handle from
% the persistant list and close the progressbar
% string - a string to be replaced in the progress bar (optional)
% titlestr - a title for the dialog box (optional)
%
% Output: handle - a graphic handle of the dialog box
%
%
% NOTE: this function uses a persistant list of handles and thier values.
% therefore, to delete a progressbar, please call the function with:
% progressbar( handle,-1 );
%
% an "abort" button is formed inside the progressbar, if the calling process
% uses the persistent function "gui_active". when the "abort" button is pressed,
% the Callback function "gui_active" changes it's value to zero, which enables
% the application to interactively stop execution
%
% Example: gui_active(1); % will add an abort button
% h = progressbar( [],0,'my test' );
% max_count = 1e+3;
% for idx = 1:max_count
% fprintf( '%d\n',idx )';
% h = progressbar( h,1/max_count );
% if ~gui_active
% break;
% end
% end
% progressbar( h,-1 );
%

MATLAB release MATLAB 6.1 (R12.1)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (14)
06 Feb 2004 Hemant Khatod

This is real good...All though I havent used it to its full potential.

18 Feb 2004 Roy Schestowitz  
14 Mar 2005 Guy Cooke

Excellent. very simple to use.

30 Nov 2005 chris p

easy to use, does the job perfectly!
thanks ohad

03 Dec 2005 Stephen Pickett

Super easy to use. Quick and to the point

10 Feb 2006 Alexandre KOZLOV

Simple to use but:
- only relative changes (i.e. no possibility to set absolute value, or reset bar);
- no way to change "Please Wait" message - I'm in France :-)
- strange abort mechanism;
I'd try to make an old good class with all properties accessible by getters/setters, including flags "show abort button" and "abort button was pressed".

06 Apr 2006 Jasper Dozer

Why not use the standard waitbar???

stop=false;
h = waitbar(0.0,'Please wait...','CreateCancelBtn','stop=true; delete(h); clear h');
set(h,'Name','optional window name');
for i=1:100
waitbar(i/100,h,['Update ' num2str(i)]);
if stop break; end
% do stuff
end
if exist('h') delete(h); end

29 Nov 2006 Ed Lawson

Thanks for the waitbar suggestion -- it does exactly what I want.

The major difference between this function & waitbar is the abort functionality.

19 Nov 2007 Genaro Longoria

Really good post

14 Feb 2008 h wei

easy and just to the point.

14 Oct 2008 Peter Schuck

works great, simple to use.

17 Nov 2008 Latif Yalcinoglu

If you use following code, then you can see the estimated process time in bar..( 'mod' is for saving the total process time)..

tic
for i=1:yourprocess
        if mod(i,100)==0
        totaltime = int32(toc*yourprocess/i);
        string = sprintf('Trace # %d/%d, Time = %d sec', i,... not, totaltime);
        waitbar(i/yourprocess,h,['' string ]);
% ...
% your process....
% ...
end

02 Jul 2009 andrey

not bad, but for 50,000 calculations workbar slows progress down by a factor of 2. Better than waitbar (a factor of 5) but still...

17 Apr 2010 Chetan

Nice utility thanks!!

Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
gui tools Ohad Gal 22 Oct 2008 07:03:06
example Ohad Gal 22 Oct 2008 07:03:06
progress bar Ohad Gal 22 Oct 2008 07:03:06
waitbar Ohad Gal 22 Oct 2008 07:03:06
abort Ohad Gal 22 Oct 2008 07:03:06
gui Ohad Gal 22 Oct 2008 07:03:06
utilities Ohad Gal 22 Oct 2008 07:03:06
button Ohad Gal 22 Oct 2008 07:03:06
abort Andres Ayala 20 Nov 2008 08:25:29
abort Abbie 09 Apr 2009 14:56:22
abort yu kay 27 Apr 2011 10:47:31

Contact us at files@mathworks.com