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!

Réponses (2)

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 le 4 Déc 2025
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 commentaires

Thomas
Thomas le 4 Déc 2025
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 le 4 Déc 2025
How about just running pause() once, outside of the for-loop, right after the msgbox()?
Mathieu NOE
Mathieu NOE le 4 Déc 2025
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 le 4 Déc 2025
Modifié(e) : Mathieu NOE le 4 Déc 2025
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 le 4 Déc 2025
Modifié(e) : Walter Roberson le 4 Déc 2025
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)

Connectez-vous pour commenter.

Catégories

En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange

Produits

Version

R2025b

Community Treasure Hunt

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

Start Hunting!

Translated by