How can I display a table alongside a plot in the same figure?

421 views (last 30 days)
I have created a plot and now I have a table of statistics that I would like to display next to the plot in the same figure. Ideally, this table would have nice formatting so that it is easy to read. How can I achieve this?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 10 Nov 2021
This can be achieved through the use of the "uifigure", "uiaxes", and "uitable" functions. First, create a figure, then an axes object to place the plot onto, and then display the table using the "uitable" function. By setting the "Position" property of the axes and table objects, you can place the table next to the plot or on top of the plot as an annotation.
Here is an example implementation:
f = uifigure('Position', [100 100 630 420]);
a = uiaxes(f, 'Position', [220 10 400 400]);
plot(a, 1:20, (1:20).^2);
t = table();
t.A = [5; 6];
t.B = [7; 9];
uitable(f, 'Data', t, 'Position', [10 10 200 400])
The output of the above code would look like this.
Reference page for "uifigure":
Reference page for "uiaxes":
Reference page for "uitable":

More Answers (0)

Categories

Find more on Develop uifigure-Based Apps in Help Center and File Exchange

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!