msgbox body text does not show up

27 次查看(过去 30 天)
Thomas
Thomas 2025-12-4,10:36
编辑: Walter Roberson 2025-12-4,17:33
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 about 1 hour 前
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 about 6 hours 前
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 个评论
Mathieu NOE
Mathieu NOE about 3 hours 前
编辑:Mathieu NOE about 3 hours 前
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 about 2 hours 前
编辑:Walter Roberson about 2 hours 前
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)

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

产品


版本

R2025b

Community Treasure Hunt

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

Start Hunting!

Translated by