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
댓글 수: 0
채택된 답변
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File 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!