Is it possible to update a uitextarea without using drawnow?

9 views (last 30 days)
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 Comment
Walter Roberson
Walter Roberson on 6 May 2023
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.

Sign in to comment.

Answers (1)

Image Analyst
Image Analyst on 6 May 2023
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 Comment
Neuropragmatist
Neuropragmatist on 6 May 2023
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.

Sign in to comment.

Categories

Find more on Data Type Identification in Help Center and File Exchange

Products


Release

R2023a

Community Treasure Hunt

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

Start Hunting!