App designer, label text is not updated

125 views (last 30 days)
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

Accepted Answer

Ameer Hamza
Ameer Hamza on 18 May 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 Comments
Eric Sargent
Eric Sargent on 9 Dec 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:

Sign in to comment.

More Answers (0)

Categories

Find more on Develop Apps Using App Designer in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!