How can I display a table alongside a plot in the same figure?
418 views (last 30 days)
Show older comments
MathWorks Support Team
on 10 Nov 2021
Answered: MathWorks Support Team
on 19 Nov 2021
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
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":
0 Comments
More Answers (0)
See Also
Categories
Find more on Develop uifigure-Based Apps in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!