Why is updating my uitable slowing down my app?

15 vues (au cours des 30 derniers jours)
Michael Van de Graaff
Michael Van de Graaff le 3 Juin 2022
Commenté : Matheus Sozza le 22 Jan 2023
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

Réponse acceptée

Michael Van de Graaff
Michael Van de Graaff le 3 Juin 2022

Plus de réponses (0)

Catégories

En savoir plus sur Develop Apps Using App Designer dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by