Code covered by the BSD License  

Highlights from
progressbar

4.91071

4.9 | 60 ratings Rate this file 124 Downloads (last 30 days) File Size: 4.65 KB File ID: #6922
image thumbnail

progressbar

by

 

15 Feb 2005 (Updated )

Simple, efficient, and user friendly replacement for waitbar.

| Watch this File

File Information
Description

This implementation of progressbar is intended to be extremely simple to use while providing a high quality user experience.

Features:
  - Can add progressbar to existing m-files with a single line of code.
  - Supports multiple bars in one figure to show progress of nested loops.
  - Optional labels on bars.
  - Figure closes automatically when task is complete.
  - Only one figure can exist so old figures don't clutter the desktop.
  - Remaining time estimate is accurate even if the figure gets closed.
  - Minimal execution time. Won't slow down code.
  - Randomized color. When a programmer gets bored...

Demo:
  n = 1000;
  progressbar % Create figure and set starting time
  for i = 1:n
      pause(0.01) % Do something important
      progressbar(i/n) % Update figure
  end

Acknowledgements

Progbar inspired this file.

This file inspired Spatial Channel Model For Mimo Simulations. A Ray Based Simulator Based On 3 Gpp Tr 25.996 V.6.1.0, Wilcoxon Signed Rank Examination, Methane Solubility, Core: Conceptual Optimization Of Rotorcraft Environment, Image Quality Index Analysis Gui, Txtprogressbar, Workbar, Movie Editor, and Hyperspectral Image Index Analysis.

MATLAB release MATLAB 7.10 (R2010a)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (85)
14 Jul 2014 Steve Hoelzer

Awadhesh: The comments at the top of the file show two ways of handling nested loops. You can adapt those to your situation. Here's one way to do it:

progressbar(0,0,0) % Init 3 bars
for i = 1:m
progressbar([],0,0) % Reset 2nd and 3rd bar
for j = 1:n
% do stuff
progressbar([],j/n) % Update 2nd bar
end
for k = 1:p
% do stuff
progressbar([],[],k/p) % Update 3rd bar
end
progressbar(i/m) % Update 1st bar
end
progressbar(1)

14 Jul 2014 Awadhesh Ranjan

Hello Steve,
I have a for loop and inside that i have 2 separate for loops. For example:
for i=1:N
for j=1:p
% my code here
end

for k=1:m
% my code here
end

end
How to use your progress bar to show the progress of all the three loops with the outermost loop being the main one?

18 Jun 2014 Jean Michel Franco  
10 Jun 2014 May Chan  
19 Jun 2013 Dhiraj  
13 May 2013 Harold

I figure out how to place the text inside of the progress bar for a single progress bar. Comment out if length(progdata) > 1 and the end for the if. Also you can change 0.99 to width/2 to move the progtext location to the center of the bar.

13 May 2013 Harold

How can I modify this so that the percentage is located in the progress bar itself, for one progress bar figure that is.

19 Feb 2013 Steve Hoelzer

sami: No, there is no way to relabel the progress bar without resetting it. I did that on purpose to keep it very simple.

18 Feb 2013 sami shalhoub

Is there a way to relabel the progress bar without reinitializing the bar?
if relable the bars it loose track with how much time is remaining

01 Feb 2013 Kaushik

Awesome submission... really liked it.

17 Jan 2013 Reza Farrahi Moghaddam  
26 Dec 2012 deema

love it!

17 Oct 2012 Steve Hoelzer

Christopher: Good idea, but the problem with a cancel button is capturing the click and doing something right away while other code is busy running. See my old comment to "Jveer" for a bit more detail.

03 Oct 2012 Christopher

With regards to cancel functionality:
Couldn't you use something like waitbar does where you use appdata() to tell it if you're cancelling?

05 Sep 2012 Emilien  
28 Jun 2012 Thitipun Chobtrong

love it!

28 Jun 2012 Thitipun Chobtrong  
20 Jun 2012 Casper  
19 Jun 2012 Ruben Luis  
06 Jun 2012 Steve Hoelzer

Francisco: I wrote and tested this code with R2010a (which is specified in the file info section at the top). I don't have an older Matlab release for testing, so you'll have to upgrade Matlab or patch the code yourself.

05 Jun 2012 Francisco de Castro

My previous comment got deleted somehow. Here it is again:
"Doesn't work for me, at least with multiple bars updated independently. The upper-level bars are never updated, only the innermost loop. The help example "% Simple multi bar" shows this. It DOES work if the bars are updated simultaneously.
Shame, because its a great piece of code.
I've got 7.7.0.471 (R2008b)"

05 Jun 2012 Francisco de Castro

I forgot, with multiple bars updated independently, it deletes the names assigned to the bars at initialization...
Thought I mentioned it.

23 May 2012 James Kerns  
20 May 2012 Avihay

Thanks, I love it

16 Apr 2012 Thomas Guillod  
09 Apr 2012 Steve Hoelzer

Boris: Thanks for the comments!

1. That would be nice, but I don't think it's possible inside progressbar itself. It might work to put a try-catch around your code and have the catch call progressbar(1) to close the bar.

2. I've tried, but can't get it work quite right. See my previous comments.

3. Also a good idea. I believe others have modified my function to work like you describe, but I've never gotten around to doing it myself.

04 Apr 2012 Rohit Mundra

As simple as it gets, but no simpler. Perfect!

28 Mar 2012 Boris

Three things:
- The progress bar should be removed when the program finishes - even when interrupted (might be a hard one)
- A cancel button to interrupt the program might be handy right there
- the bar should integrate into the interface a bit better (docking - or in status bar of editor)
Otherwise - nice work!

21 Mar 2012 SSOI SS

Very GOOD !!

09 Mar 2012 nguyen

so good

31 Jan 2012 Dmitry  
11 Jan 2012 Zach  
07 Dec 2011 Hamid.R Ansary  
15 Nov 2011 Y.S.  
09 Nov 2011 Tom Hissel

Hey Benjamin. Your addition of embedding the progress bar into the GUI seems very interesting. How did you do that? Can you post or mail your file? Id love to see how its done(I didnt manage to do that).

Also Steve, thanks for making this nice tool:)

12 Oct 2011 Benjamin Bratton

This is a great piece of code that I use all the time. I appreciate how well commented the code is.

I made some updates so that the bar(s) can be embedded into a gui. I would be happy to send it your way if you like.

12 Oct 2011 Benjamin Bratton  
06 Oct 2011 Steve Hoelzer

Matthew: Thanks! As for label updates, I'm still waiting for a patch. ;)

05 Oct 2011 Matthew Schroeder

Great work! Any word on the ability to update labels during execution without resetting the figure?

12 Aug 2011 Boris Schauerte  
14 Jun 2011 Steve Hoelzer

Gianluca: Thanks for the comments!

I'm not familiar with MATLAB's parallel computing features, so I don't know for sure what's going on. My guess is that you can't update local figures from "workers", so you need to monitor their status somehow and update progressbar locally. Let me know if you figure out how to make it work.

10 Jun 2011 Gianluca

Thanks Steve for this fantastic tool, very simple, handy and efficient.

Is there any way to make it work in parallel computing. I run a simple test just using you "simple bar" example and it does not update the bar under the "spmd" function. Any clue of the reason?

08 Jun 2011 Brian Katz  
26 May 2011 Steve Hoelzer

Daniel: Those sound like interesting features. I'd like see how you did it, so please send your code my way. Thanks!

23 May 2011 Daniel Baur

Wow, really great work! Love it and it works like a charm.

For my purposes though, I took the liberty of editing around in your code a bit. What I did:
- Changed from function to class, so multiple instances can be run easily and without interfering with each other.
- Incorporated label changes during execution. The bar_text property can be edited and applies again when the figure updates.
- Made the calculation of the remaining time more accurate by taking the mean of all iterations already done as iteration time.

I could send you my modified file if you'd like to have a look!

16 May 2011 Steve Hoelzer

Halil: There is no way to update labels without resetting the whole progress bar. I'd welcome code to implement that feature... :)

You're right about the remaining time calculation. I did it that way because of my concept of what multiple bars represent. I always think of the top bar as progress of the overall task, and other bars as progress of sub tasks. For an example of how I would use it, look at the "Fancy multi bar" demo in the progressbar's comments.

14 May 2011 halil sen

sorry about the mess, firefox failure. i wish there were a delete comment button...

anyways, first of all thank you for this efficient, fast, and handy function. i wonder whether it is possible to update the 'Label' of the bars or not. OR is it doable?

cheers

EDIT: also, one last thing as far as I can see, the 'remaining time' calculations only depend on the first bar's runtime but this is sort of misleading. maybe, the way how the remaining time is calculated can be optional (e.g. max/min of the remaining time of all bars or the bar(s) that will be used in calculations may be specified by the user or both options at the same time etc.) nevertheless, stating this calculation fact in the Help would be nice and explanatory.

btw, pardon me if i'm wrong about the way of time calculations.

14 May 2011 halil sen  
14 May 2011 halil sen  
14 May 2011 halil sen  
12 Apr 2011 Steve Hoelzer

Ayla: It will take a little work to put progressbar in your own GUI. You'll have to change how the bar is created so it draws in the right place in your GUI instead of its own figure. Good luck!

09 Apr 2011 Ayla

I really like your progress bar! Would it be possible to integrate it in a custom GUI created by myself instead of displaying it in a separate window? Thanks!

01 Mar 2011 Steve Hoelzer

Egli: The bar closes automatically when you reach 100%. You can force it to close at any time by calling progressbar(1).

01 Mar 2011 Egli Vorfi

Excellent !

Just wanted to know if it's possible to close the bar automatically once it's over.

08 Feb 2011 Sky Sartorius

Quite superior to waitbar. One feature I'd really like to see is the ability to update the progress bar label(s) without resetting the progress bar and timer, letting you inform the user exactly what process or subprocess is taking so long. Excellent job on this very handy function.

25 Jan 2011 jon erickson

Beautiful, easy to use. A wonder matlab doesn't include this in their standard distro. Love matlab file exchange. Thanks, Steve!

13 Oct 2010 Light Den

It's just perfect!Thank U !

11 Oct 2010 Steve Hoelzer

Jveer: I've played with adding pause and abort buttons but I was never totally happy with how it turned out. The main problem is that those buttons are unresponsive in the time period between calls to progressbar. You click, and then wait until the next call to progressbar before anything happens. In some of my own code, that could be 10 minutes or a half hour. And sometimes the click isn't captured so you never get the desired behavior at all. So far I've chosen to do without rather than add a half-broken feature.

09 Oct 2010 Jveer

any chance of seeing 'pause', 'resume' and 'abort' functionality in future versions?

09 Oct 2010 James Tursa

Nice! Easy to use. Great submission.

08 Oct 2010 Jveer

fantastic contribution!

30 Aug 2010 Naor Movshovitz  
24 Jan 2010 Muhammad Muzzamil Luqman

Thanks Steve for this wonderful contribution :)

27 Aug 2008 jongchul kim

slsls

25 Jun 2008 Khaledov Kh

Needs to name the process bar...

19 Apr 2008 Abel Brown

lol, so simple and nice. makes ppl think you're awesome at matlab when they see a progbar :)

like this much better than waitbar!!! Nice work

13 Dec 2007 Quan Quach

I made some modifications to this great app and you can find it here. Added an abort functionality and an output parameter so that when the progress bar is closed, you can use the output parameter to break from the for loop.

http://www.blinkdagger.com/matlab/matlab-gui-tutorial-progress-status-bar

23 Mar 2007 A L P

Have problem with this function and plotting graph.
This is the error that appear:
>??? Invalid handle object.
>
>Error in ==> progressbar at 202
>set(progpatch,'XData',[0 fractiondone >fractiondone 0])
>
>Error in ==> Untitled at 17
> progressbar(inc/nbpt)

07 Aug 2006 Quintin Coetzee

Thak you for this substitute for waitbar.
I will be using it in software I am developing for my 4th year engineering report.

02 Jul 2006 Luis Aponte

This function is great and very simple to use.

27 Apr 2006 Dave Douglas

This thing is simple to use and looks fantastic. Thanks!!!

11 Feb 2006 Tom Nagel

I love it. So easy, so helpful.

05 Jan 2006 Suhas Gajre

One of the beautiful codes I have seen!

Very much useful for programmers like me who have to wait for agonizingly long time to finish the code :))

06 Dec 2005 Bharat Rangan

Great work. Very useful little piece. A possible addition is the ability to add another string during inititation which could specify the task at hand. Just my 0.02. Thanks a ton

11 Nov 2005 Wolfgang Garn

It is really terrific. Thank you.
If you like to have two, three or more progressbars, just copy the m-file to progressbar2, progressbar3, ...

06 Oct 2005 Liz Leibman

Thank you! Its just perfect! Now my program looks so good!

27 Sep 2005 Wolfgang Garn

An interesting extension would be to start more than one progressbars.

15 Sep 2005 Michal Mackiewicz  
19 Aug 2005 Jean-Vincent LE LAN  
15 Jun 2005 Fred Plourde

Very simple and yet, very efficient ! It took me less than 2 minutes to add it successfully to my project

05 Apr 2005 Ryan Scheppele

Nifty little routine!

11 Mar 2005 Tim Faughn

Fantastic!

22 Feb 2005 Antoni Josep Canós Marín

Very good!!. It should be included in future releases of MATLAB.

17 Feb 2005 jiro d

very slick!

16 Feb 2005 Alan Brooks

Very simple to use and very efficient. I like the ability to use it in one line of code.

Updates
08 Oct 2010

Major overhaul to support multiple bars and add labels.

08 Oct 2010

Major overhaul to support multiple bars and add labels.

Contact us