How do I put a uitable in a tiledlayout?
46 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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
0 Kommentare
Akzeptierte Antwort
Catalytic
am 28 Mai 2024
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 Kommentare
Weitere Antworten (1)
Matt J
am 24 Mai 2024
Bearbeitet: Matt J
am 24 Mai 2024
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
Siehe auch
Kategorien
Mehr zu Interactive Control and Callbacks finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!