File Exchange

image thumbnail


version (4.65 KB) by Steve Hoelzer
Simple, efficient, and user friendly replacement for waitbar.


Updated 08 Oct 2010

View Version History

View License

Editor's Note: This file was selected as MATLAB Central Pick of the Week

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

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

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

Cite As

Steve Hoelzer (2021). progressbar (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (174)

Danielle Bennett

fab thanks

Rashed Herb

guang xu

hasan afwan

hi man
khaleej trend



Jeroen Hogema

Brillant! So easy to use, yet so rich!


Carlos Borau

Just awesome. Wish I had found this ten years earlier...

Adam Danz

Great work. Two suggestions for small improvements. 1) the fontsize in r2020a is a lot smaller than the fontsize that appears in the image on this page but that's easy enough to adjust within the function. 2) When colors are dark, switch to a different font color or avoid dark colors altogether so the text within the bars can be easily seen.

Terry Furqan


Sibi chakaravarthy R



Evert Merkx

mega mike

Raheel Mushtaq

Omar Al-Louzi

Michael Gostein

Kieren Smith


Great submission. I use it literally every day. A tweak I put in to prevent the figure from being overwritten during program execution:

Change line 196 from progfig = figure('Name'...'none); to the following:
progfig = figure(999);
progfig.Units = 'normalized';
progfig.Position = [left bottom width height];
progfig.NumberTitle = 'off';
progfig.Resize = 'off';
progfig.MenuBar = 'none';

Additionally, I created a dummy function called my_closereq. Inside is nothing:

function my_closereq(src,callbackdata)

Then, you can set the following property:
progfig.CloseRequestFcn = @my_closereq

This will prevent the figure from closing when you close all. To manually close the figure, you can either do "close all force" or "delete(999)". The progressbar function will close itself automatically at the end, so there isn't any real need.



Samuel Wagner

Alice Liu

Naing Lin Tun

aamir irshad

Hi, I am facing a bug in my usage of progressbar.
I am using it in multibar mode and the problem is that when my outermost loop completes once,
the bar gets minimized automatically. At every outer cycle, the progress-window is getting minimized.
On the other hand, it is working fine.

Luis Henríquez

Thanks, it's been very useful using this progressbar.

Though, I've got a question, is it possible to add this progressbar to a user interface I'm creating?
I'm kind of new in Matlab.

Julien Furrer

Kieren Smith

Brian moore

Md Kamrul Hasan

Great tool, thanks for your work


Julian Freedland

Vijesh Soorya Rao

Awesome :)

Elio Di Claudio

Anish Nathie

Chris H

This function works great! It doesn't slow down code and it gives you a good representation of how long your code will take to run!

Sergey Galushin


Excellent function and much quicker than most others out there. Thanks for sharing.

Brian Katz

A great function that I use regularly. Made a small modification (around line 197) to bypass 'docked' WindowStyle if that is the default setting:

progfig = figure(...
'Units', 'normalized',...
'Position', [left bottom width height],...
'NumberTitle', 'off',...
'Resize', 'off',...
'MenuBar', 'none' );

Note that the 'WindowStyle' definition must come before Position or it is in conflict with the 'docked' behavior.

Dino Enriquez

Filippo Gasco

Great work!
Is it possible to pass the progressbar to subfunctions? I have a multiple m-file script and i would like to keep a global progress bar that traces also all the subsections.

Stefan Angelow

Jeong Ryou

Derek Flett

Just what I was looking for. Simple to implement!

Mohamed Abd Allah


Jon Adsersen



Really good useful progress bar. Great submission, thank you. I added the following code to the progressbar.m so that the progressbar is prompt at about the centre of my custom parent Figure:

% Code to place the progress bar about the centre of a target gui.
% Please make sure to get the correct Figure Position using the Tag
% value.
figHandles = findall(0, 'Type', 'figure');
pos = [];
for i = 1:numel(figHandles)
hndl = figHandles(i);
strcmpi(hndl.Tag, 'parent');
pos = figHandles(1).Position;

if isempty(pos)
% Initialize progress bar figure
left = (1 - width) / 2;
bottom = (1 - height) / 2;
left = pos(1) + pos(3)/4;
bottom = pos(2) + pos(4)/2;

cj gs


Excellent submission. A minor recommendation would be to add the 'WindowStyle','normal' pair to the figure(...) command. I default to having figure windows docked so things like this which do belong as detached windows need this pair explicitly.

Vincent Kather

Steve Hoelzer

Caleb: Drawing/plotting commands work on the specified axis, or the "current" axis. See help for "gca" and "axes".

Caleb Thomas

Is there a way to stop matlab from plotting axis in the progress bar figure? I am trying to use it to monitor my frame capture progress when making animations, but matlab keeps putting my plots inside the progress bar figure window, which causes some pretty obvious complications. Any help is appreciated

Will Grant

Replace lines 257-258 with the following to allow passing in char label updates to already created progressbar...

if ~ischar(input{ndx})
progdata(ndx).fractiondone = input{ndx};
progdata(ndx).clock = clock;
set(progdata(ndx).proglabel, 'String', input{ndx});


% init
progressbar(0, 0, 'label here')

% update
progressbar([], 0.5, 'completed this step....')

Som Dhulipala



Great work. Cheers !

Andrea Del Prete

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


Exactly what I seek for,

Gene L


Carlos Garcia

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

Carlos Garcia

Werner Badenhorst

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

John Ferris

Awesome simple utility


Steve Hoelzer

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!



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

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!


super useful

thank you

Alfredo Capobianchi

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 ( 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

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!



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


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



Steve Hoelzer

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)

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?

Steve Hoelzer

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.


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?


Easy to use and beautiful! I love it!

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
for k = 1:p
% do stuff
progressbar([],[],k/p) % Update 3rd bar
progressbar(i/m) % Update 1st bar

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

for k=1:m
% my code here

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

Jean Michel Franco

May Chan



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.


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

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


Awesome submission... really liked it.


love it!

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.


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


Thitipun Chobtrong

love it!

Thitipun Chobtrong


Ruben Luis

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.

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

Francisco de Castro

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

James Kerns


Thanks, I love it

T. Guillod

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.

Rohit Mundra

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


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!


Very GOOD !!


so good



Hamid.R Ansary


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

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.

Benjamin Bratton

Steve Hoelzer

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

Matthew Schroeder

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

Boris Schauerte

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.


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

Steve Hoelzer

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

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?


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

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!


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

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

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

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.


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

James Tursa

Nice! Easy to use. Great submission.


fantastic contribution!

Naor Movshovitz

Thanks Steve for this wonderful contribution :)

jongchul kim


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.


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


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.

MATLAB Release Compatibility
Created with R2010a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!