Why is updating my uitable slowing down my app?

15 次查看(过去 30 天)
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

采纳的回答

Michael Van de Graaff

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Develop Apps Using App Designer 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by