msgbox body text does not show up

Hi,
I'm using a msgbox(...) to let the user know that a calculation is in progress. Once the calculation is done, I delete the msgbox. In MATLAB versions up to R2024b, this worked fine. However, starting in R2025a, the msgbox window and the OK button appear, but the body text does not show up (see screenshots below). Here is a code example to reproduce the problem:
h = msgbox('Calculating result, please wait...');
for i=1:100000000 % consume some time doing calculations
a(i) = 42;
end;
delete(h); % delete the msgbox
Result in MATLAB 2024b:
Result in MATLAB 2025b:
Inserting a drawnow() statement after creating the msgbox does not solve the problem.
How can I fix this? Is there an alternative approach to achieve a similar functionality?
Thanks!

답변 (2개)

Fangjun Jiang
Fangjun Jiang 2025년 12월 4일

0 개 추천

I use waitbar() for this purpose. It could be fancy but don't over-done it.
f=waitbar(0,'in progress','Name','My App');
for k=1:10
pause(1);
waitbar(k/10, f);
end
Mathieu NOE
Mathieu NOE 2025년 12월 4일

0 개 추천

seems to me now you have to use strings (double quote) and no more char array
this works for me (R2025a)
h = msgbox("Calculating result, please wait..."); % input is a string ""
for i=1:20 % consume some time doing calculations
a(i) = 42;
pause(0.1)
end
delete(h); % delete the msgbox

댓글 수: 5

Thomas
Thomas 2025년 12월 4일
Thanks for the quick reply. Indeed, if I put a "pause(0.1)" statement in the calculation routine, the text in the msgbox shows up (independent of whether it is a string or char array). It just doesn't feel "right" to use a pause statement to get the code working. Besides, if you have to do a lengthy calculation, you don't want to slow it down further by putting pause statements into the code....
Fangjun Jiang
Fangjun Jiang 2025년 12월 4일
How about just running pause() once, outside of the for-loop, right after the msgbox()?
Mathieu NOE
Mathieu NOE 2025년 12월 4일
yiu're right, I just followed what the doc shows as examples (string) - char array still works. Your situation is really funny because indeed without the pause effect the text does not show up.
Mathieu NOE
Mathieu NOE 2025년 12월 4일
편집: Mathieu NOE 2025년 12월 4일
seems to me a quick workaround is to ad a bit of pause before you start the long computation loop - in my understanding , this 0.1 s pause will let matlab finish the display of the msgbox text.
this seem to do the trick on my side :
h = msgbox("Calculating result, please wait...");
pause(0.1)
for i=1:5e7 % consume some time doing calculations
a(i) = i;
end
delete(h); % delete the msgbox
Walter Roberson
Walter Roberson 2025년 12월 4일
편집: Walter Roberson 2025년 12월 4일
I experimented with putting in a drawnow() before the loop. I thought at first that it worked, but I was mistaken; either way the text of the message box does not show up until after the loop (R2025b)

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

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품

릴리스

R2025b

질문:

2025년 12월 4일

편집:

2025년 12월 4일

Community Treasure Hunt

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

Start Hunting!

Translated by