How to insert a table under three subplots in a figure

I am trying to put a table under three plots in the same figure, but when I run the code only the table is visible and the plots dissapear. Below I let the code that I am using.
if true
%figures
%figure for the raw data
figure
h=surf(vec,vec,B.*mask);
set(h,'LineStyle','none');
colormap default ;
hc=colorbar;
hc.Label.String = 'nm';
title('Graph of the Lens')
%figure for the zernikes
figure
g=surf(vec,vec,z_Zern);
set(g,'LineStyle','none');
colormap default ;
gc=colorbar;
gc.Label.String ='nm';
title('Graph of the zernikes')
%figure for the subtraction
figure
h=surf(vec,vec,D);
set(h,'LineStyle','none');
colormap default;
hc=colorbar;
hc.Label.String = 'nm';
title('Subtraction')
%Plots in 2D
figure;
subplot(2,2,1);
imagesc(vec,vec,B);
daspect([1 1 1]);
cb1=colorbar;
cb1.Label.String = 'nm';
caxis([-70 110])
title('Raw data');
%================
subplot(2,2,2);
imagesc(vec,vec,z_Zern);
daspect([1 1 1]);
cb2=colorbar;
cb2.Label.String = 'nm';
caxis([-70 110])
title('Zernike data');
%================
subplot(2,2,3);
imagesc(vec,vec,D);
daspect([1 1 1]);
cb3=colorbar;
cb3.Label.String = 'nm';
caxis([-70 110])
title('Subtraction');
%================
subplot(2,2,4);
tt = {'PV';'rms'};
raw_data = [PV_1;x_rms_1];
zernike_data= [PV_2;x_rms_2];
residual_data = [PV_3;x_rms_3];
T = table(raw_data,zernike_data,residual_data,'RowNames',tt);
uitable('Data',T{:,:},'ColumnName',T.Properties.VariableNames,...
'RowName',T.Properties.RowNames,'Units', 'Normalized', 'Position',[0, 0, 1, 1]);
end

1 Kommentar

...,'Units', 'Normalized', 'Position',[0, 0, 1, 1]...
You are explicitly telling the table to fill the whole figure so that is what it is doing, and since you add it last it is on top. If you added the axes last then they would be on top of the table.

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Adam Danz
Adam Danz am 23 Aug. 2018
Bearbeitet: Adam Danz am 23 Aug. 2018
It's not that the plot disappears. The plot is under your UI table. You're setting the position of the UI table as
...'Position',[0, 0, 1, 1]...
which consumes the entire figure. Instead, get the position of the 4th subplot and use that position to set the UI table. I changed 4 lines from your code and marked them as " % NEW".
h = subplot(2,2,4); % NEW
hPos = get(h, 'Position'); % NEW
tt = {'PV';'rms'};
raw_data = [PV_1;x_rms_1];
zernike_data= [PV_2;x_rms_2];
residual_data = [PV_3;x_rms_3];
T = table(raw_data,zernike_data,residual_data,'RowNames',tt);
uitable('Data',T{:,:},'ColumnName',T.Properties.VariableNames,...
'RowName',T.Properties.RowNames,'Units', 'Normalized', 'Position', hPos); % NEW
set(h, 'Visible', 'Off') % NEW
end

4 Kommentare

Marta
Marta am 18 Okt. 2022
Verschoben: Adam Danz am 18 Okt. 2022
I tried to use uitable following the structure suggested here, but I get the error:
Error using uitable
Functionality not supported with figures created with the figure function.
How did you manage to add the table (iutable) in the figure?
Thanks.
@Marta what MATLAB release are you using?
2022b
@Marta, please provide a minimal working example that reproduces this error.
Here's a minimal working example of my answer that runs in R2022b.
figure
h = subplot(2,2,4);
T = array2table(rand(10));
uitable('Data',T{:,:},'Units',h.Units,'Position',h.Position);
h.Visible = 'Off';

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Data Distribution Plots finden Sie in Hilfe-Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by