MATLAB: How to put a waitbar in an existing figure in MATLAB 7.13 (R2011b)

MATLAB

I would like to put a waitbar in an existing figure, such as a GUI figure, instead of having it appear in a separate window.

Best Answer

There is no single command for placing a WAITBAR inside an existing GUI or figure.
As a workaround, one can construct a wait bar from axes and rectangle objects. Please see the following functions for an example.
function waitbar_init(h_axes)
%h_axes is an axes handle
delete(get(h_axes,'Children'));
axis(h_axes,[0 1 0 1]);
axis(h_axes,'off');
rectangle('Position',[0 0 1 1],'Parent',h_axes,'FaceColor','w','EdgeColor','k');
function waitbar_fill(h_axes,fill)
c = get(h_axes,'Children');
if length(c) == 2
if fill > 0
set(c(1),'Position',[0 0 fill 1]);
elseif fill == 0
delete(c(1));
end
elseif fill > 0
rectangle('Position',[0 0 fill 1],'Parent',h_axes,'FaceColor','r','EdgeColor','k');
end