App designer, label text is not updated

8 visualizaciones (últimos 30 días)
J_Matlab
J_Matlab el 18 de Mayo de 2018
Comentada: Eric Sargent el 9 de Dic. de 2020
Hello,
I'm working on an app in Matlab App Designer and I noticed that my calls to change the text of a label or not executed properly. Clicking on a button starts a function, which in turn calls several other functions. I want to give the user some feedback during the function so it is clear that the script didn't crash. Here is my example code:
function do_several_things(app)
app.Label_status.Text = 'Status: Now doing x...';
do_x();
app.Label_status.Text = 'Status: now doing y...';
do_y();
app.Label_status.Text = 'Status: now doing z...';
do_z();
imshow(app.some_img, [], 'Parent', app.ImMain);
app.Label_status.Text = 'Status: Done...';
end
When I run the script, only the last message "Status: Done..." is shown. The functions take around 10 seconds, so I am sure that the other text messages are not shown. I also tried commenting out the last text update and the imshow command, then the script does not display any messages while running and after having finished displays the third text "Status: no dowing z...". Commenting out more showed the same pattern. Why is the text not updated at the correct moment? Is a label the wrong object for my aim and if so what other options do I have?
edit: I am using Matlab 2018a

Respuesta aceptada

Ameer Hamza
Ameer Hamza el 18 de Mayo de 2018
Use drawnow to force the app to update the label
app.Label_status.Text = 'Status: Now doing x...';
drawnow
do_x();
app.Label_status.Text = 'Status: now doing y...';
drawnow
do_y();
. . .
. . .
  3 comentarios
Ameer Hamza
Ameer Hamza el 18 de Mayo de 2018
You are welcome.
Eric Sargent
Eric Sargent el 9 de Dic. de 2020
I would avoid using drawnow in this context.
I would propose using uiprogressdlg() to give users feedback about the status of a process.
Or if you want it on a button you can use the solution proposed here from Adam Danz:

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Package and Share Apps en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by