No BSD License  

Highlights from
cwaitbar.m

2.5

2.5 | 2 ratings Rate this file 3 Downloads (last 30 days) File Size: 5.52 KB File ID: #4121
image thumbnail

cwaitbar.m

by Rasmus Anthin

 

04 Nov 2003 (Updated 06 Nov 2003)

A generalization of the waitbar function. Handles nested for loops.

| Watch this File

File Information
Description

An extension/generalization of the MATLAB's WAITBAR function. Used when you want to show progress in "nested computations". Supports different coloring of bars other than the default red color. See example below on usage.

%%%%%

CWAITBAR Display compound wait bar.
H = CWAITBAR(X,TITLE) creates and displays wait bars of
fractional lengths X and with one title string TITLE.
The handle to the compound waitbar figure is returned in H.
X values should be between 0 and 1.
Each subsequent call to cwaitbar, CWAITBAR([BAR X]),
extends the length of the bar BAR to the new position X.
The first bar is the topmost bar and is BAR = 1 which
corresponds to the outermost loop.
H = CWAITBAR(X,TITLE) where TITLE is a cellstring with same
number of titles as there are fractional lengths in X.
Suitable for showing the bars' corresponding loop indices.
H = CWAITBAR(X,TITLE,COLOR) where COLOR is the color of the
bars. COLOR is either a color code character (see PLOT) or
an RGB vector. The default color is red. COLOR can also be
a cell array with same number of elements as there are bars
in the cwaitbar figure.

The order of the elements in vector X and cell arrays TITLE
and COLOR which is consistent with the bar number BAR is:
The first element corresponds to the first bar at the top
of the figure which in turn corresponds to the outermost loop.

CWAITBAR is typically used inside nested FOR loops that
performs lengthy computations.

Examples:
cwaitbar([.3 .2 .7],'Please wait...'); %single title

h = cwaitbar([0 0 0],{'i','j','k'},{[.8 .2 .8],'b','r'});
for i=1:5,
% computations %
for j=1:10
% computations %
for k=1:100
% computations %
cwaitbar([3 k/100])
end
cwaitbar([2 j/10])
end
cwaitbar([1 i/5])
end
close(h)

See also WAITBAR.

%%%%%%%%%%%

More functions available at:
http://www.etek.chalmers.se/~e8rasmus/eng/matlab_programs.html

MATLAB release MATLAB 5.2 (R10)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (4)
05 Nov 2003 Urs Schwarz (us)

there's a typo in your w3 page refernce: progrmas should read programs (of course). please, be careful not to frustrate your customers :-) us

22 Feb 2007 Feng Gan

set(p,'xdata',xpatch,'erase','none')
   set(l,'xdata',xline)
   
   %%% add by Feng Gan
   str=[num2str(x) '% finished......'];
   title(a,str)

09 Dec 2007 (anonymous) (anonymous)

Thank you for sharing your waitbar code - I like how it looks. Question: How can I make cwaitbar behave like the original waitbar that does NOT stay on top of everything else? It can get annoying when I cannot type anything in another application such as a web-browser while I am using cwaitbar on Matlab. I would appreciate any suggestion on where to edit in your code. I am running Matlab on Mac OSX. Thank you.

18 Apr 2009 Jveer

looks great but doesnt show remaining time!!!

Please login to add a comment or rating.
Updates
06 Nov 2003

Changed description/help.

06 Nov 2003

Bar number BAR is now "flipped". BAR = 1, corresponds to the topmost bar and BAR = n, where n is the number of bars, corresponds to the bottom bar (innermost loop).

Tag Activity for this File
Tag Applied By Date/Time
gui tools Rasmus Anthin 22 Oct 2008 07:09:15
example Rasmus Anthin 22 Oct 2008 07:09:15
waitbar Rasmus Anthin 22 Oct 2008 07:09:15
nested Rasmus Anthin 22 Oct 2008 07:09:15
loops Rasmus Anthin 22 Oct 2008 07:09:15
progress Rasmus Anthin 22 Oct 2008 07:09:15

Contact us at files@mathworks.com