cwaitbar.m

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

2.9K Downloads

Updated Thu, 06 Nov 2003 11:15:08 +0000

No License

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

Cite As

Rasmus Anthin (2023). cwaitbar.m (https://www.mathworks.com/matlabcentral/fileexchange/4121-cwaitbar-m), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R10
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!
Version Published Release Notes
1.0.0.0

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