Code covered by the BSD License  

Highlights from
progressbar

4.90164
4.9 | 67 ratings Rate this file 112 Downloads (last 30 days) File Size: 4.65 KB File ID: #6922 Version: 1.2
image thumbnail

progressbar

by

Steve Hoelzer (view profile)

 

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, Qu De X Ms, Workbar, Movie Editor, Txtprogressbar, 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 (96)
20 Aug 2015 Steve Hoelzer

Steve Hoelzer (view profile)

Anthony: You're not the first person to ask... see the older comments. It is certainly possible to integrate progressbar into an app, but I've never done it and it won't work as-is. You'd need to make it draw into your GUI instead of its own little window. Good luck!

Comment only
10 Aug 2015 Anthony  
07 Aug 2015 Anthony

Hey Steve,

First off the code runs very well but I have one question regarding implementing it with a GUI. I was wondering if there is any way to add the progressbar window to a currently existing GUI window instead of the progressbar being its own separate window? Is this possible?

Best Regards

11 May 2015 Jonathan

Nice work :)
I've added a customized close function which stop the main program. It is not very elegant as it's base on removing the path to "progressbar.m" but it works (without bringing change in the main).

11 May 2015 Jonathan  
24 Feb 2015 John

John (view profile)

 
06 Jan 2015 Steve Hoelzer

Steve Hoelzer (view profile)

Alfredo: Without seeing your code I can't help much. The examples at the top of the file show how to do it: progressbar([], 0.3)

Comment only
06 Jan 2015 Alfredo Capobianchi

Hello, first of all, thank you very much for your submission.
Second, when I update the second progressbar, labels are deleted.
I have MATLAB 2014b.
Any idea?

02 Dec 2014 Steve Hoelzer

Steve Hoelzer (view profile)

raunak: If your inner loop calls progressbar(1) then the bar is closed and the labels are lost. You can initialize the labels in the outer loop so they are recreated for each inner loop.

Comment only
28 Nov 2014 raunak

raunak (view profile)

Steve, I have a question.
When I use a loop inside a for loop which does not contain progressbar ftn call, then the progress bar naming disappears in the main progressbar loop call. How to tackle i?

Comment only
27 Nov 2014 Adrien

Adrien (view profile)

Easy to use and beautiful! I love it!

14 Jul 2014 Steve Hoelzer

Steve Hoelzer (view profile)

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)

Comment only
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

Dhiraj (view profile)

 
13 May 2013 Harold

Harold (view profile)

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.

Comment only
13 May 2013 Harold

Harold (view profile)

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

Comment only
19 Feb 2013 Steve Hoelzer

Steve Hoelzer (view profile)

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

Comment only
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

Comment only
01 Feb 2013 Kaushik

Awesome submission... really liked it.

17 Jan 2013 Reza Farrahi Moghaddam  
26 Dec 2012 deema

deema (view profile)

love it!

17 Oct 2012 Steve Hoelzer

Steve Hoelzer (view profile)

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.

Comment only
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!

Comment only
28 Jun 2012 Thitipun Chobtrong  
20 Jun 2012 Casper

Casper (view profile)

 
19 Jun 2012 Ruben Luis  
06 Jun 2012 Steve Hoelzer

Steve Hoelzer (view profile)

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.

Comment only
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)"

Comment only
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.

Comment only
23 May 2012 James Kerns  
20 May 2012 Avihay

Avihay (view profile)

Thanks, I love it

16 Apr 2012 Thomas Guillod  
09 Apr 2012 Steve Hoelzer

Steve Hoelzer (view profile)

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.

Comment only
04 Apr 2012 Rohit Mundra

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

28 Mar 2012 Boris

Boris (view profile)

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

nguyen (view profile)

so good

31 Jan 2012 Dmitry

Dmitry (view profile)

 
11 Jan 2012 Zach

Zach (view profile)

 
07 Dec 2011 Hamid.R Ansary  
15 Nov 2011 Y.S.

Y.S. (view profile)

 
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:)

Comment only
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.

Comment only
12 Oct 2011 Benjamin Bratton  
06 Oct 2011 Steve Hoelzer

Steve Hoelzer (view profile)

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

Comment only
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

Steve Hoelzer (view profile)

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.

Comment only
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

Brian Katz (view profile)

 
26 May 2011 Steve Hoelzer

Steve Hoelzer (view profile)

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

Comment only
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

Steve Hoelzer (view profile)

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.

Comment only
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

Steve Hoelzer (view profile)

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!

Comment only
09 Apr 2011 Ayla

Ayla (view profile)

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

Steve Hoelzer (view profile)

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

Comment only
01 Mar 2011 Egli Vorfi

Excellent !

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

Comment only
08 Feb 2011 Sky Sartorius

Sky Sartorius (view profile)

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.

Comment only
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 !

Comment only
11 Oct 2010 Steve Hoelzer

Steve Hoelzer (view profile)

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.

Comment only
09 Oct 2010 Jveer

Jveer (view profile)

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

Comment only
09 Oct 2010 James Tursa

James Tursa (view profile)

Nice! Easy to use. Great submission.

08 Oct 2010 Jveer

Jveer (view profile)

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

Comment only
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 1.1

Major overhaul to support multiple bars and add labels.

08 Oct 2010 1.2

Major overhaul to support multiple bars and add labels.

Contact us