フィルターのクリア

How do I put a uitable in a tiledlayout?

95 ビュー (過去 30 日間)
Ben
Ben 2024 年 5 月 23 日 22:37
コメント済み: Matt J 2024 年 5 月 31 日 20:17
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 日 22:38
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 日 20:10
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 日 20:17
@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 日 5:55
編集済み: Matt J 2024 年 5 月 24 日 14:27
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 日 19:59
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 日 20:50
編集済み: Matt J 2024 年 5 月 29 日 11:03
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 Center および File ExchangeLine Plots についてさらに検索

製品


リリース

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by