フィルターのクリア

Why is there a long "busy" time when drawing gridlayout

1 回表示 (過去 30 日間)
Johnny Birch
Johnny Birch 2020 年 10 月 3 日
Hi MATLAB'ers
I am developing an app in app designer where I want to have a dashboard-like tableoverview with 40-60 rows and 16 columns. For this I am using gridlayout because I need:
  • multilines in some cells
  • Images in some cells
It only takes about 3-4 seconds to run the code and prepare the gridlayout, but MATLAB keeps "busy" for additional 20-40 seconds. How can this be and is there anything I can do to optimize speed performance?
I am doing this in app designer and want to show the grid in a panel. However, I have written some dummy data below as an example for creating the grid in a figure, by running the script.
clear
%%PREPARE DUMMY DATA
NoOfRows = 60;
testData= cell(NoOfRows,16);
for h = 1:16
testData(:,h) = cellstr(char(randi([65 80],NoOfRows,1)));
end
testData = cell2table(testData);
testData.Properties.VariableNames = {'Navn','blabla','F','Team','I/S','Veg','Fisk','RF','Mandag','Tirsdag','Onsdag','Torsdag','Fredag','Bemærkninger','Møder','Start/slut'};
%%PREPARE GRID LAYOUT
BottonFontColor = [0 0 1];
CellColor = [0.2 0.4 0.6];
FullHeaderColor = [0 0 0.5];
TestColor1 = [0.1 0.1 0.1];
TestColor2 = [0.6 0.6 0.6];
TestColor3 = [1 1 1];
TestColor4 = [0.4 0.4 0.4];
TestColor5 = [0.5 0.5 0.5];
TestColor6 = [0.6 0.6 0.6];
TestColor7 = [0.7 0.7 0.7];
TestColor8 = [0.8 0.8 0.8];
TestColor9 = [0.9 0.9 0.9];
TestColor10 = [0.1 0.1 1.0];
%Create gridlayout
fig = uifigure('Position',[100 100 440 320]);
grid = uigridlayout(fig,[height(testData) 16],'Scrollable','on');
grid.Visible = 'off';
%Set grid properties
grid.ColumnSpacing = 0;
grid.RowSpacing = 0;
RowHeight = cell(1,height(testData));
RowHeight(:) = {90};
RowHeight(1) = {45};
grid.RowHeight = RowHeight;
grid.ColumnWidth = {100,25,100,35,35,35,35,'1x','1x','1x','1x','1x',230,110,65,50};
%Vectorize Data table
test = table2cell(testData);
test = test';
test = test(:);
%create a table row indicator correlated to the original table dimensions
row = 0;
%loop over every cell in the vectorized table (cellarray)
for i = 1:height(testData)*16
% returns the remainder after division of i by 16
n = mod(i,16);
switch n
case 1 %Name
row = row+1;
if row == 1
uit = uitextarea(grid,'Value', test{i},"FontSize",14,'Editable','on');
uit.BackgroundColor = FullHeaderColor;
else
uit = uibutton(grid,'Text','Test1');
uit.FontColor = BottonFontColor;
end
case 2 %Fase
uit = uitextarea(grid,'Value', test{i},"FontSize",14,'Editable','on');
if row == 1
uit.BackgroundColor = FullHeaderColor;
else
uit.BackgroundColor = CellColor;
end
case 3 %Team
uit = uitextarea(grid,'Value', test{i},"FontSize",12,'Editable','on');
if row == 1
uit.BackgroundColor = FullHeaderColor;
else
uit.BackgroundColor = CellColor;
end
case 4 %I/S (icecream / snickers)
if row == 1
uit = uitextarea(grid,'Value', test{i},"FontSize",14,'Editable','on');
uit.BackgroundColor = FullHeaderColor;
else
uit = uitextarea(grid,'Value', "",'Editable','on');
uit.BackgroundColor = CellColor;
end
case 5 %Veg
if row == 1
uit = uitextarea(grid,'Value', test{i},"FontSize",14,'Editable','on');
uit.BackgroundColor = FullHeaderColor;
else
uit = uitextarea(grid,'Value', "",'Editable','on');
uit.BackgroundColor = CellColor;
end
case 6 %Fish
if row == 1
uit = uitextarea(grid,'Value', test{i},"FontSize",14,'Editable','on');
uit.BackgroundColor = FullHeaderColor;
else
uit = uitextarea(grid,'Value', "",'Editable','on');
uit.BackgroundColor = CellColor;
end
case 7 %Refeed
uit = uitextarea(grid,'Value', test{i},"FontSize",14,'Editable','on');
if row == 1
uit.BackgroundColor = FullHeaderColor;
else
uit.BackgroundColor = CellColor;
end
case 8 %Mandag
if row == 1
uit = uitextarea(grid,'Value', test{i},"FontSize",16,'Editable','on');
uit.BackgroundColor = TestColor1;
else
uit = uitextarea(grid,'Value', test{i},"FontSize",14,'Editable','on');
uit.BackgroundColor = TestColor2;
end
case 9 %Tirsdag
if row == 1
uit = uitextarea(grid,'Value', test{i},"FontSize",16,'Editable','on');
uit.BackgroundColor = TestColor3;
else
uit = uitextarea(grid,'Value', test{i},"FontSize",14,'Editable','on');
uit.BackgroundColor = TestColor4;
end
case 10 %Onsdag
if row == 1
uit = uitextarea(grid,'Value', test{i},"FontSize",16,'Editable','on');
uit.BackgroundColor = TestColor5;
else
uit = uitextarea(grid,'Value', test{i},"FontSize",14,'Editable','on');
uit.BackgroundColor = TestColor6;
end
case 11 %Torsdag
if row == 1
uit = uitextarea(grid,'Value', test{i},"FontSize",16,'Editable','on');
uit.BackgroundColor = TestColor7;
else
uit = uitextarea(grid,'Value', test{i},"FontSize",14,'Editable','on');
uit.BackgroundColor = TestColor8;
end
case 12 %Fredag
if row == 1
uit = uitextarea(grid,'Value', test{i},"FontSize",16,'Editable','on');
uit.BackgroundColor = TestColor9;
else
uit = uitextarea(grid,'Value', test{i},"FontSize",14,'Editable','on');
uit.BackgroundColor = TestColor10;
end
case 13 %Bemærkninger
uit = uitextarea(grid,'Value', test{i},"FontSize",12,'Editable','on');
if row == 1
uit.BackgroundColor = FullHeaderColor;
else
uit.BackgroundColor = TestColor1;
end
case 14 %Statusmøde
uit = uitextarea(grid,'Value', test{i},"FontSize",12,'Editable','on');
if row == 1
uit.BackgroundColor = FullHeaderColor;
else
uit.BackgroundColor = CellColor;
end
case 15 %Vægt
if row == 1
uit = uitextarea(grid,'Value', "Vægt","FontSize",14,'Editable','on');
uit.BackgroundColor = FullHeaderColor;
else
uit = uibutton(grid,'Text',{'Blabla'});
uit.BackgroundColor = TestColor5;
end
case 0 %StartSlutDato
uit = uitextarea(grid,'Value', test{i},"FontSize",14,'Editable','on');
if row == 1
uit.BackgroundColor = FullHeaderColor;
else
uit.BackgroundColor = TestColor6;
end
end
end
%Finalize gridlayout properties
grid.Visible = 'on';

回答 (0 件)

カテゴリ

Help Center および File ExchangeDevelop Apps Using App Designer についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by