Why is updating my uitable slowing down my app?

조회 수: 15 (최근 30일)
Michael Van de Graaff
Michael Van de Graaff 2022년 6월 3일
댓글: Matheus Sozza 2023년 1월 22일
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
Michael Van de Graaff 2022년 6월 3일

추가 답변 (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