How do I put a waitbar in an existing figure in MATLAB 7.8 (R2009a)?

1 visualización (últimos 30 días)
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.
  1 comentario
Aurelien Queffurust
Aurelien Queffurust el 26 de Mayo de 2011
I would really appreciate to see this question/answer as a Technical Note on the technical support web site.
Thanks,
Aurélien

Iniciar sesión para comentar.

Respuesta aceptada

Doug Hull
Doug Hull el 13 de En. de 2011
To put a waitbar in an existing figure, you must transfer all the elements of a waitbar out of the default separate figure window and put it them on the existing figure.
Specifically, you must assign the parent of all these elements to be a handle to your existing figure rather than the handle to the separate figure. See the following code as an example of how to do this:
%grabs a handle 'f' to a figure.
f = figure;
% Creates a WAITBAR in a new figure (by default)
h = waitbar(0,'Please wait...'); %
% The child of the waitbar is an axes object. Grab the axes
% object 'c' and set its parent to be your figure f so that it now
% resides on figure f rather than on the old default figure.
c = get(h,'Children');
set(c,'Parent',f); % Set the position of the WAITBAR on your figure
set(c,'Units','Normalized','Position',[.5 .5 .3 .05]);
% Close the default figure
close(h);
% The above steps only need to occur once to place the waitbar on the figure.
% Now when you go to use the WAITBAR you can just call the waitbar with two
% inputs: waitbar(x,h) where x is how much of the bar you want filled and f
% is the handle to your figure.
steps = 1000;
for step = 1:steps
% computations take place here
waitbar(step / steps,f)
pause(.01)
end
  2 comentarios
Aurelien Queffurust
Aurelien Queffurust el 26 de Mayo de 2011
Hi Dough,
This code works fine in R2010b but fails in R2011a :
It returns the error message :
??? Error using ==> waitbar>extractHandles at 280
Couldn't find waitbar handles.
Error in ==> waitbar at 89
handles = extractHandles(whichbar);
Error in ==> Untitled at 25
waitbar(step / steps,f)
The waitbar code has changed in 11a .
Walter Roberson
Walter Roberson el 26 de Mayo de 2011
I do not have 2011a to look at the code with, but I would _speculate_ that it might be necessary to set the figure Tag to 'TMWWaitbar'

Iniciar sesión para comentar.

Más respuestas (1)

Jelle
Jelle el 9 de Feb. de 2011
Hello,
I have a problem with this function when i want to update the message corresponding to the waitbar. When the waitbar has an own figure this command works fine:
waitbar(x,figurehandle,'updated message')
But when figurehandle corresponds to the figure where the waitbar is placed in, then the update message function does not work anymore. This error is shown:
??? Error using ==> waitbar at 106
Improper arguments for waitbar.
Caused by:
Error using ==> set
Conversion to double from cell is not possible.
How can I solve this problem?
Kind regards,
Jelle
  1 comentario
Walter Roberson
Walter Roberson el 9 de Feb. de 2011
I just looked at the waitbar code as of 2008b, and it is definitely not designed for the possibility that the figure might have a line, patch, or axes other than those that belong to the waitbar. In narrow situations, though, the crash wouldn't happen until it went to update the message.

Iniciar sesión para comentar.

Categorías

Más información sobre App Building en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by