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

 채택된 답변

Ameer Hamza
Ameer Hamza 2018년 5월 18일

3 개 추천

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

J_Matlab
J_Matlab 2018년 5월 18일
Works perfectly, thanks for the advice!
Ameer Hamza
Ameer Hamza 2018년 5월 18일
You are welcome.
Eric Sargent
Eric Sargent 2020년 12월 9일
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:

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

질문:

2018년 5월 18일

댓글:

2020년 12월 9일

Community Treasure Hunt

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

Start Hunting!

Translated by