Tables and Graphs Display

20 vues (au cours des 30 derniers jours)
Thore
Thore le 27 Mai 2016
Réponse apportée : Aashray le 21 Août 2025 à 14:17
Hi
I have created a code that outputs a lot of information and I wish to display this information using tables and graphs. I have the code for the tables and graphs and it works well but when the code runs and the figures display they are all over the screen and the tables are often misplaced inside the figure. Is there some way to code them into specific positions inside the figure and make the display better? Please see below for my code. Any suggestions, also for better syntax, is highly appreciated. Thanks in advance!
%Get Screensize scrsz = get(groot,'ScreenSize');
%Test Subplot figure('OuterPosition',[scrsz(4)/1.1 scrsz(4)/2 scrsz(3)/2 scrsz(4)/2]); subplot(2,2,1);hist(DRGPS_distance_next_point);title('Histogram 1') subplot(2,2,2);hist(DRGPS_distance_next_point);title('Histogram 2') subplot(2,2,3);hist(DRGPS_distance_next_point);title('Histogram 3') subplot(2,2,4);hist(DRGPS_distance_next_point);title('Histogram 4') set(gcf,'numbertitle','off','name','Statistical Analysis')
%Test Control Chart figure('Position',[1 1 scrsz(3)/2 scrsz(4)/1]); figure(2) hfigure = figure(2); set(hfigure, 'Menubar', 'none'); set(hfigure, 'ToolBar', 'none'); controlchart(TestControlChart,'chart',{'xbar','r'});
%STAT TABLE figure('Position',[scrsz(4)/1.1 scrsz(2)/1 scrsz(3)/2 scrsz(4)/2.6]) Stat_table = figure(3); set(Stat_table, 'Menubar', 'none'); set(Stat_table, 'ToolBar', 'none'); columnname = {'Value','St. Dev.','Variance','P-value'}; rowname = {'Avg. Total Distance','Avg. Distance > Error Margin','Avg. Distance < Error Margin','Avg. Total # Satellites','Avg. # Satellites > Error Margin','Avg. # Satellites < Error margin','Avg. Total Hdop','Avg. Hdop > Error Margin','Avg. Hdop < Error Margin'}; % Create the uitable s_table = uitable(Stat_table, 'Data', Stat_matrix,... 'ColumnName', columnname,... 'RowName', rowname); % Set width and height s_table.Position(3) = s_table.Extent(3); s_table.Position(4) = s_table.Extent(4);
%D_TABLE figure('Position',[scrsz(4)/1.1 scrsz(3)/4 scrsz(3)/2 scrsz(4)/4]) D_table = figure(4); columnnames = {'Total','Distance > Error Margin','Distance < Error Margin'}; rownames = {'File contains:'}; d_table = uitable(D_table,'Data',D_count_matrix,... 'ColumnName',columnnames,... 'RowName',rownames); d_table.Position(3) = d_table.Extent(3); d_table.Position(4) = d_table.Extent(4);

Réponse acceptée

Aashray
Aashray le 21 Août 2025 à 14:17
Hello @Thore!
The original implementation had several separate figure windows for histograms, control chart, and tables, each positioned manually using scrsz. This led to windows overlapping or tables being misplaced.
By using uifigure with a uigridlayout, you can arrange axes and tables neatly in one window. Each item (histogram, control chart, table) sits in a grid cell that resizes automatically.
I have created a simple sample solution for your reference:
%% Dummy data
DRGPS_distance_next_point = randn(500,1)*10 + 100; % histogram data
TestControlChart = randn(25,5) + 10; % control chart data
Stat_matrix = rand(9,4); % stat table
D_count_matrix = randi([0 100],1,3); % D table
%% Dashboard Figure
f = uifigure('Name','Full Dashboard','Position',[100 100 1400 900]);
% 3 rows, 2 columns
gl = uigridlayout(f,[3 2]);
gl.RowHeight = {'1.5x','1x','0.8x'}; % relative row heights
gl.ColumnWidth = {'1x','1x'};
%% Row 1: Four Histograms (original Figure 1 content)
ax1 = uiaxes(gl); histogram(ax1,DRGPS_distance_next_point); title(ax1,'Histogram 1');
ax2 = uiaxes(gl); histogram(ax2,DRGPS_distance_next_point); title(ax2,'Histogram 2');
ax3 = uiaxes(gl); histogram(ax3,DRGPS_distance_next_point); title(ax3,'Histogram 3');
ax4 = uiaxes(gl); histogram(ax4,DRGPS_distance_next_point); title(ax4,'Histogram 4');
ax1.Layout.Row = 1; ax1.Layout.Column = 1;
ax2.Layout.Row = 1; ax2.Layout.Column = 2;
ax3.Layout.Row = 2; ax3.Layout.Column = 1;
ax4.Layout.Row = 2; ax4.Layout.Column = 2;
%% Row 2: Control Chart (spans both columns)
ax5 = uiaxes(gl);
ax5.Layout.Row = 2; ax5.Layout.Column = [1 2];
controlchart(TestControlChart,'chart',{'xbar','r'});
title(ax5,'Control Chart');
%% Row 3: Stat Table (left) and D Table (right)
colnames = {'Value','St. Dev.','Variance','P-value'};
rownames = {'Avg. Total Distance','Avg. Distance > Error Margin',...
'Avg. Distance < Error Margin','Avg. Total # Satellites',...
'Avg. # Satellites > Error Margin','Avg. # Satellites < Error margin',...
'Avg. Total Hdop','Avg. Hdop > Error Margin','Avg. Hdop < Error Margin'};
t1 = uitable(gl,'Data',Stat_matrix,...
'ColumnName',colnames,'RowName',rownames);
t1.Layout.Row = 3; t1.Layout.Column = 1;
colnames2 = {'Total','Distance > Error Margin','Distance < Error Margin'};
rownames2 = {'File contains:'};
t2 = uitable(gl,'Data',D_count_matrix,...
'ColumnName',colnames2,'RowName',rownames2);
t2.Layout.Row = 3; t2.Layout.Column = 2;
The Major changes from the original implementation are:
  • Replaced figure windows with one uifigure.
  • Used uigridlayout to automatically arrange plots and tables in a grid instead of manually using scrsz and pixel positions.
  • Replaced deprecated hist with histogram.
  • For tables, used uitable inside the grid, so they always resize automatically.
  • Control chart is embedded in the dashboard instead of opening in its own floating window.
Also attaching the documentation links of the functions used for reference:

Plus de réponses (0)

Catégories

En savoir plus sur Specifying Target for Graphics Output dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by