Why is updating my uitable slowing down my app?

8 visualizzazioni (ultimi 30 giorni)
Why does my uitable get sluggish when i'm updating it?
(Solved, posted for community reference)
I have an app. The app has a table. The table is updated as i use the app, either manually or programatically.
The table is updated, and if a condition in the code is met, I change the color of a cell to indicate that visually. this is done using the addStyle (https://www.mathworks.com/help/matlab/ref/matlab.ui.control.table.addstyle.html) function. If a different conditions is met, I switch the style back to what it was, again using addStyle. I did not remove the old styles
DON'T FORGET TO REMOVE STYLES!! The styles simply accumulate in the uitable object.
Here is a MWE demonstrating how this happens:
f = uifigure;
t = uitable(f);
t.Data = magic(4);
nsty = 80;
tic
for ii = 1:10
timetable(t,nsty)
removeStyle(t); %Clean up clean up everybody do your share!
end
toc
disp("And now just YOLOing it.")
tic
for ii = 1:10
timetable(t,nsty) %now we are not removing the styles, the loop will slow way down.
end
toc
function timetable(t,nstyle)
for ii = 1:nstyle
c = [rand(),rand(),rand()];
s = uistyle('BackgroundColor',c);
addStyle(t,s,'column',2)
end
a = t.StyleConfigurations;
var = whos('a');
disp(['The size (in bytes) of the StyleConfigurations field of the table is ',num2str(var.bytes)])
end

Risposta accettata

Michael Van de Graaff
Michael Van de Graaff il 3 Giu 2022

Più risposte (0)

Categorie

Scopri di più su Migrate GUIDE Apps in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by