Is it possible to update a uitextarea without using drawnow?

7 次查看(过去 30 天)
Hi all,
I am building an app using the app designer, in the window I have a uitextarea where I post updates to the user, something like this:
app.OutputTextArea.Value{end+1} = sprintf('Hello world');
I can also programatically scroll the text area down so the user can see the lastest message:
scroll(app.OutputTextArea,'bottom');
However, if the code is running quite quickly many messages are not shown until the current task is completed, at which point the text area is updated all at once, which defeats the purpose of giving the user a current status update.
The text area can be updated using a call to drawnow:
drawnow;
But as I understand it this updates all of the displayed items, which is a waste of resources when the only thing changing is the text area.
I would like to just update the text area and nothing else.
Drawnow does not accept an axis as an input, so I can't tell it to just update one thing, however I have tried refreshdata which can accept a specific axis input:
refreshdata(app.OutputTextArea);
However, this doesn't seem to work for uitextareas.
Is there a function I am unaware of that does what I want? Or should I use something other than a uitextarea to update the user?
Thank you for any suggestions.
  1 个评论
Walter Roberson
Walter Roberson 2023-5-6
My understanding is that there are internal "dirty" flags that optimize not having to reprocess graphics objects that have not been changed (it gets a bit more complicated than that because overlayed graphics can be affected by underlays changing.) So if the text area is the only thing that has changed, then processing drawnow should not be expensive.
I could be wrong about the internal workings.

请先登录,再进行评论。

回答(1 个)

Image Analyst
Image Analyst 2023-5-6
Not that I know of, other than putting in a pause(), which would just slow down your app also. Sometimes what I do is to call drawnow only every, say, 20th iteration
for k = 1 : 100000
if rem(k, 20) == 0
drawnow;
end
end
  1 个评论
Neuropragmatist
Neuropragmatist 2023-5-6
Hmmm, I have had to use a pause elsewhere because I have tabs and the SelectedTab property was not updating quickly enough. As you say though, I don't really want to introduce an unnecessary pause as that will add time.
My problem is also not iterations, just that the textarea is alongside other plots and drawing them can be slow.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Data Type Identification 的更多信息

产品


版本

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by