File Exchange

image thumbnail


version (4.97 KB) by Daniel Terry
Graphically monitors the completion of iterations in a parfor loop


Updated 29 Jan 2016

View License

Creates a graphical progress indicator to monitor the completion of iterations in a long-running loop. The usage is similar to MATLAB's built in waitbar function, but it works with parfor loops in addition to ordinary for loops. A temporary file is written to by worker threads to record the completion of each parfor iteration and a timer periodically updates the progress bar. Through optional arguments that are passed to waitbar internally, the user can set a cancel button or any other option that waitbar supports. For now, only local execution is supported, but the function can be modified to replace tempdir with a location accessible by all workers.
Example usage:

N=50; %total number of parfor iterations
hbar = parfor_progressbar(N,'Please wait...'); %create the progress bar
parfor i=1:N,
pause(rand); % computation
hbar.iterate(1); % update progress by one iteration
close(hbar); % close the progress bar

Comments and Ratings (23)

Would be nice to add percentage value to the progress bar


Alex (view profile)


AA (view profile)

Great function. Just what I needed. It is not restricted to parfor loops. I just used it with spmd blocks. Thanks.


Dave Lee

When I compare two cases of running with and without hbar.iterate(1), I see this progress bar makes parfor loop run more slowly


John (view profile)

Great function, thanks!

Eric Chadwick

Great function! It is a very nice feature in any code using parfor loops. I was just wondering if you ever considered Mo.En's suggestion of adding a percentage or a remaining time estimation?

Ali Komai


M V (view profile)

Why I get the following error?

Error while evaluating TimerFcn for timer 'parfor_progressbar'
No public property 'ipcfile' for class 'parfor_progressbar'


Mo.En (view profile)

Works pretty much as expected.

I have two suggestions:
1. Add percentage value, to the progress bar.
2. Add a general "Remaining Time" estimation


if a cancel button is added, the waitbar can not be deleted:

hbar = parfor_progressbar(10,'Please wait...','CreateCancelBtn','@() disp(''cancelling'')');
close(hbar); % does not delete hbar
delete(hbar); % does not delete hbar either


sorry, it should be

hbar = parfor_progressbar(10,'Please wait...','CreateCancelBtn','@() disp(''cancelling'')');


Shaan (view profile)


Daniel Terry

Tested and working on MATLAB 2016b.

Liang Wang

Great tool, useful for 2014 and 2015, but not working for 2016a anymore.


Daniel Terry

Thank you for your kind review Geert.

I have some ideas of how to do this. The tricky part is that GUI objects are not updated within the parfor loop. It may be possible to add a callback for the waitbar window in the GUI thread that deletes the parfor_progress.txt status file to tell the parfor threads to stop.

I will keep you posted if I come up with something that works.

Nicely made and very useful. Thanks!
Just one question: I would like that upon closing the waitbar, the parfor loop stops (for instance, if the user sees that it will take ages for the algorithm to finish, he/she can choose to stop the processing).
So far, I did not manage to do this. My code

if isempty(hbar.wbh)

does not seem to work because the object handle wbh is not empty upon closing the waitbar. Any idea how I could manage this?

Thanks in advance. Cheers, Geert


JDmuuc (view profile)

Great submission, thanks.

Daniel Terry

This error was fixed in the recent version. Please try it again.


when running it, the waitbar do not progress. and there is an worning:

Warning: This functionality is no longer supported under the -nodisplay and -noFigureWindows startup options. ...


Now supports both MATLAB 2014 and 2015. Using a class instead of graphics handle to fix warnings in worker threads and make it compatible with 2014. If you had a problem with the previous version, please try it again.

Added a picture and changed the title to emphasize that this is an extension of the built-in waitbar function.

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

Discover Live Editor

Create scripts with code, output, and formatted text in a single executable document.

Learn About Live Editor