File Exchange

image thumbnail

progressbar

version 1.2 (4.65 KB) by

Simple, efficient, and user friendly replacement for waitbar.

4.85135
84 Ratings

176 Downloads

Updated

View License

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

Comments and Ratings (116)

Great work. Cheers !

Great code!This simple and useful!

Only one problem (and fix): there is a warning given at each bar update when the default interpreter is set to 'latex'. I fixed it by explicitly setting the interpreter in the two ext object to 'none' (lines 221 and 226).

Dimitry

Exactly what I seek for,
Thanks

Gene L

Gene L (view profile)

skippic

Does someone have the version that allows you to put figure into custom GUI ?

Fantasties! Baie dankie (many thanks)! Simple, effective and easy to adjust bar lengths and widths to personal taste.

John Ferris

Awesome simple utility

PierreC

Steve Hoelzer

Steve Hoelzer (view profile)

John: Thanks for the comments. (1) Only allowing one progressbar was an intentional design choice. (It's described as a feature up above!) When I'm writing new code or debugging I often crash or dbstop and this prevents the old progressbar(s) from hanging around forever. (2) That is certainly possible and might be useful. I encourage you to try it yourself and post back here!

Mike

Mike (view profile)

John

John (view profile)

Hi Steve,

I can see two improvements. One, is to return / take a handle to the figure, so that multiple progress bars can be implemented, in order to track different completion times or subprocesses. And, second, the scripts I'm running a long time. So estimating the completion time on the outer loop isn't too helpful. Could you include the estimated completion for each loop, possibly as text over the bar for each loop.

sun wei

Fábio Nery

Steve Hoelzer

Steve Hoelzer (view profile)

Alfredo: I really don't know how parfor loops work. You'd need some way to know when each "iteration" completes so you can update the progressbar. If you figure it out, please post back here!

samart

samart (view profile)

super useful

thank you

Hi Steve, would it be possible to integrate it in a parfor loop? I've tried to call it inside a parfor loop with argument provided by function parfor_progress (http://www.mathworks.com/matlabcentral/fileexchange/32101-progress-monitor--progress-bar--that-works-with-parfor/) but it doesn't display progress. Thank you!

James O'Brien

For the very time-intensive code I have, this is a great way to know that it is running - along with the progress. The "waitbar" function added a huge latency, so I just had an ugly text display "% Complete" in the window. Matlab sorely needs to update these type of functions.

This is great for showing off to the upper management, and looks much more professional.
  
Thanks Steve. Nice work!

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!

Anthony

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

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

Jonathan

John

John (view profile)

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)

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?

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.

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?

Adrien

Adrien (view profile)

Easy to use and beautiful! I love it!

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)

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?

May Chan

Dhiraj

Dhiraj (view profile)

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.

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.

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.

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

Kaushik

Awesome submission... really liked it.

deema

deema (view profile)

love it!

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.

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?

Emilien

love it!

Casper

Casper (view profile)

Ruben Luis

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.

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

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

James Kerns

Avihay

Avihay (view profile)

Thanks, I love it

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.

Rohit Mundra

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

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!

SSOI SS

Very GOOD !!

nguyen

nguyen (view profile)

so good

Dmitry

Dmitry (view profile)

Zach

Zach (view profile)

Y.S.

Y.S. (view profile)

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

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.

Steve Hoelzer

Steve Hoelzer (view profile)

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

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

Boris Schauerte

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.

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?

Brian Katz

Brian Katz (view profile)

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!

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!

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.

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.

halil sen

halil sen

halil sen

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!

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!

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

Egli Vorfi

Excellent !

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

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.

jon erickson

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

Light Den

It's just perfect!Thank U !

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.

Jveer

Jveer (view profile)

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

James Tursa

James Tursa (view profile)

Nice! Easy to use. Great submission.

Jveer

Jveer (view profile)

fantastic contribution!

Naor Movshovitz

Thanks Steve for this wonderful contribution :)

jongchul kim

slsls

Khaledov Kh

Needs to name the process bar...

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

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

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)

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.

Luis Aponte

This function is great and very simple to use.

Dave Douglas

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

Tom Nagel

I love it. So easy, so helpful.

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

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

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, ...

Liz Leibman

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

Wolfgang Garn

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

Michal Mackiewicz

Jean-Vincent LE LAN

Fred Plourde

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

Ryan Scheppele

Nifty little routine!

Tim Faughn

Fantastic!

Antoni Josep Canós Marín

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

jiro d

very slick!

Alan Brooks

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

Updates

1.2

Major overhaul to support multiple bars and add labels.

1.1

Major overhaul to support multiple bars and add labels.

MATLAB Release
MATLAB 7.10 (R2010a)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video