How do I put a uitable in a tiledlayout?

조회 수: 46 (최근 30일)
Ben
Ben 2024년 5월 23일
댓글: Matt J 2024년 5월 31일
Hello,
I'm trying to graph some data in a particular way. I need to make the same 4 plots over a variable number of iterations of data and put them all into one fixed-size figure. I need one of these 4 plots to be a table displaying some info about the data. I tried using uitable, but it errors when you try to pass it a tiled layout as it's parent. I could put the figure handle as the parent, but that seems difficult to position and size correctly.
How can I accomplish what I'm trying to do? Is there an alternative to uitable I could use?
Here is my example code and output:
%variable number of data files to plot; could be 4,8, or 15
thingsToPlot=8;
%creates square for tiles depending on # of files; 2x for double wide plots
n=2*ceil(sqrt(thingsToPlot));
%Parent Figure; Size must stay the same to allow exporting to ppt to be consistent
fig = figure('Name','Example','NumberTitle','off','units','inches','Position',[4 2 10 6.4]);
%Tiled layout parent container, child of fig
TL=tiledlayout(fig,n,n,'TileSpacing','tight');
for i=1:thingsToPlot
%Child container; Need to plot a 2x2 tile for each file and it in parent container
tl=tiledlayout(TL,2,2,'Padding','tight','TileSpacing','tight');
tl.Title.String=['Iteration ' num2str(i)];
%double wide tiles so they're more visible;
tl.Layout.TileSpan=[2 2];
%Positioning math to make the 2x2 tiles fit and sequence correctly
pos=2*i-1;
tl.Layout.Tile=pos+n*floor(pos/n);
%example data
data=rand(3,5);
nexttile(tl)
plot(data(1,:))
nexttile(tl)
plot(data(2,:))
nexttile(tl)
plot(data(3,:))
nexttile(tl)
tab=table();
tab.A=data(1,:);
tab.B=data(2,:);
tab.C=data(3,:);
%want to put a table here
% uit=uitable(tl,tab);
end

채택된 답변

Catalytic
Catalytic 2024년 5월 28일
Must it be a table that the user can modify interactively? If not, then you could use the attached non-UI version of uitable (courtesy of ChatGPT).
%variable number of data files to plot; could be 4,8, or 15
thingsToPlot=8;
%creates square for tiles depending on # of files; 2x for double wide plots
n=2*ceil(sqrt(thingsToPlot));
%Parent Figure; Size must stay the same to allow exporting to ppt to be consistent
fig = figure('Name','Example','NumberTitle','off','units','inches','Position',[4 2 10 6.4]);
%Tiled layout parent container, child of fig
TL=tiledlayout(fig,n,n,'TileSpacing','tight');
for i=1:thingsToPlot
%Child container; Need to plot a 2x2 tile for each file and it in parent container
tl=tiledlayout(TL,2,2,'Padding','tight','TileSpacing','tight');
tl.Title.String=['Iteration ' num2str(i)];
%double wide tiles so they're more visible;
tl.Layout.TileSpan=[2 2];
%Positioning math to make the 2x2 tiles fit and sequence correctly
pos=2*i-1;
tl.Layout.Tile=pos+n*floor(pos/n);
%example data
data=rand(3,5);
nexttile(tl)
plot(data(1,:))
nexttile(tl)
plot(data(2,:))
nexttile(tl)
plot(data(3,:))
ax=nexttile(tl);
axisTable(ax, data',{'A','B','C'})
end
  댓글 수: 4
Ben
Ben 2024년 5월 31일
I can't change the dimensions of the figure because it needs to be exported to a powerpoint.
I was able to get somewhere by changing the decimal format and messing with the axis positions, so now it's legible.
Matt J
Matt J 2024년 5월 31일
@Ben you should Accept-click Catalytic's answer if you managed to get it working for you.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Matt J
Matt J 2024년 5월 24일
편집: Matt J 2024년 5월 24일
If you are going to be inserting uitables, it would be advisable to use UI graphics elements everywhere else too,
fig=uifigure;
G=uigridlayout(fig,[3,3]);
k=0;
for i=1:8
p=uipanel(G,'Title',"Iteration "+i);
g=uigridlayout(p,[2,2]);
for j=1:3
k=k+1;
ax(k) = uiaxes(g);
end
uitable(g,'Data',rand(3,3));
end
for i=1:numel(ax)
plot(ax(i),rand(1,5));
end
  댓글 수: 2
Ben
Ben 2024년 5월 28일
I don't really like the look of these uifigures. Can I put ui tables in nested layouts, Matt?
Matt J
Matt J 2024년 5월 28일
편집: Matt J 2024년 5월 29일
No, but you can set the uipanel properties so that the figure looks more like a conventional tildedlayout, e.g.,
p=uipanel(G,'Title',"Iteration "+i,...
'TitlePosition','centertop','FontSize',16,'BorderWidth',0);

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by