Loop through grid layout takes FOREVER. How can I optimize the code?
2 views (last 30 days)
Show older comments
I am trying to create an app with many text areas (80x12) in a gridlayout. I want to fill each grid with a individual text taken from a cell array. However, in the code example below I am just using {['test1',newline,'test2']} for all of them. But in the real example each text.value is different. I am looping over each textarea in the gridlayout and it is working as intended. However, it takes FOREVER (75.101076 seconds). Is there a way to speed up the process?
tic
fig = uifigure('Position',[100 100 440 320]);
%fig.WindowState = 'maximized';
g = uigridlayout(fig,[80 12],'Scrollable','on');
g.ColumnSpacing = 0;
g.RowSpacing = 0;
g.ColumnWidth = {150,50,20,50,150,50,50,50,50,50,150,'fit'};
g.RowHeight = {50,50,50,50,50,50,50,50,50,50,...
50,50,50,50,50,50,50,50,50,50,...
50,50,50,50,50,50,50,50,50,50,...
50,50,50,50,50,50,50,50,50,50,...
50,50,50,50,50,50,50,50,50,50,...
50,50,50,50,50,50,50,50,50,50,...
50,50,50,50,50,50,50,50,50,50,...
50,50,50,50,50,50,50,50,50,50};
for j = 1:12
for i = 1:80
txa = uitextarea(g,'Value', {['test1',newline,'test2']});
txa.Layout.Row = i;
txa.Layout.Column = j;
if i == 3
txa.BackgroundColor = 'yellow';
end
if i == 8 && j == 5
txa.BackgroundColor = 'green';
end
end
end
toc
Elapsed time is 75.101076 seconds.
Below is an example of the output
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/293438/image.png)
0 Comments
Answers (0)
See Also
Categories
Find more on Develop Apps Using App Designer in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!