How to indicate that GUI is busy running?

I would like to know how to indicate in my GUI that MATLAB is currently busy running some piece of code (e.g. a long computation). Currently, there is no indication in the GUI that the code is running, causing the user to wonder whether it is working or just not responsive.

 Respuesta aceptada

Titus Edelhofer
Titus Edelhofer el 12 de Jul. de 2011
Hi Kyle,
two typical main ways to do this: in your callback do
set(handles.figure1, 'pointer', 'watch')
drawnow;
% your computation
set(handles.figure1, 'pointer', 'arrow')
This shows the hour glass during the callback. If the callback indeed takes longer, use function "waitbar" to indicate progress ...
Titus

4 comentarios

Kyle
Kyle el 12 de Jul. de 2011
Editada: Walter Roberson el 31 de Ag. de 2020
set(handles.figure1, 'pointer', 'watch')
drawnow;
hmm isit place this be4 the section of code where its matlab going to be busy a while. then place the below code at the end of the callback?
% your computation
set(handles.figure1, 'pointer', 'arrow')
Walter Roberson
Walter Roberson el 12 de Jul. de 2011
Editada: Walter Roberson el 8 de Jul. de 2020
The "% your computation" comment is the place you would put the code that will keep MATLAB occupied.
I would use slightly different code, though:
oldpointer = get(handles.figure1, 'pointer');
set(handles.figure1, 'pointer', 'watch')
drawnow;
% your computation goes here
set(handles.figure1, 'pointer', oldpointer)
That is, I prefer not to assume that the pointer was 'arrow' before.
Aash
Aash el 4 de Mayo de 2018
I tried doing this and it is giving this error Error using matlab.ui.control.UIControl/set There is no pointer property on the UIControl class.
Error in Control>error_Callback (line 435) set(handles.error, 'pointer', 'watch')
What does it mean?
You can only set the Pointer for a figure, not for a uicontrol.
fig = ancestor(handles.error, 'figure');
oldpointer = get(fig, 'pointer');
set(fig, 'pointer', 'watch');
drawnow;
% your computation goes here
set(fig, 'pointer', oldpointer)

Iniciar sesión para comentar.

Más respuestas (3)

Kyle
Kyle el 12 de Jul. de 2011

0 votos

btw how to use function "waitbar" to indicate progress.
does matlab know to compute the time its going to be busy?

1 comentario

Sean de Wolski
Sean de Wolski el 12 de Jul. de 2011
You have to manually update waitbar - look at the example in
doc waitbar

Iniciar sesión para comentar.

Aash
Aash el 9 de Mayo de 2018
My pointer is changing to the loading while computation but it isnt coming back to the orignal arrow after the code stops executing. Here is my code
oldpointer = get(handles.figure1, 'pointer');
set(handles.figure1, 'pointer', 'watch')
drawnow;
%code that runs
set(handles.figure1, 'pointer', oldpointer)

2 comentarios

Ahmer Shahid
Ahmer Shahid el 13 de En. de 2019
How can I use this in app designer?
it's giving me error.
Error using matlab.ui.Figure/set
Functionality not supported with figures created with the uifigure function. For more information, see Graphics Support in App Designer.
syed Rahim
syed Rahim el 12 de Jun. de 2020
isn't handles a GUIDE only graphics structure. For APP designer it should be App.Figure1.

Iniciar sesión para comentar.

Jan Siegmund
Jan Siegmund el 8 de Jul. de 2020
Editada: Jan Siegmund el 31 de Ag. de 2020

0 votos

Users that looked for a waitbar style solution should have a look at https://de.mathworks.com/help/matlab/ref/uiprogressdlg.html which is basically waitbar but with an up to date look.

Categorías

Más información sobre App Building en Centro de ayuda y File Exchange.

Preguntada:

el 12 de Jul. de 2011

Editada:

el 31 de Ag. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by