how do I plot a table to a figure?

55 ビュー (過去 30 日間)
Jason
Jason 2015 年 11 月 3 日
編集済み: Jason 2015 年 11 月 17 日
I'm playing with tables because I liked how it's displayed and I'd like to display the table in a figure. Is there a simple way to do this (built in function?) or will I need to create a function that will do this somehow?
Example
LastName = {'Smith';'Johnson';'Williams';'Jones';'Brown'};
Age = [38;43;38;40;49];
Height = [71;69;64;67;64];
Weight = [176;163;131;133;119];
BloodPressure = [124 93; 109 77; 125 83; 117 75; 122 80];
T = table(Age,Height,Weight,BloodPressure,'RowNames',LastName)
T =
Age Height Weight BloodPressure
___ ______ ______ _______________
Smith 38 71 176 124 93
Johnson 43 69 163 109 77
Williams 38 64 131 125 83
Jones 40 67 133 117 75
Brown 49 64 119 122 80
I'd like T displayed in a figure that looks like it's displayed in the command window. Any ideas?
Thanks!

採用された回答

Walter Roberson
Walter Roberson 2015 年 11 月 3 日
Tlines = strsplit( evalc(T), '\n');
monofont = get(0,'FixedWidthFontName');
h = uicontrol('Style', 'edit', 'String', Tlines, 'Enable', 'disable', 'Font', monofont, 'Position', ......);
  2 件のコメント
Jason
Jason 2015 年 11 月 3 日
Hi Walter, Thanks for the code, but evalc(T) doesn't work with a table. Am I supposed to convert the table to some other format first?
Jason
Jason 2015 年 11 月 17 日
編集済み: Jason 2015 年 11 月 17 日
I figured out what I think Walter was doing.
If I replace the first line with
Tlines = strsplit('disp(evalc(T))', '\n');
the rest works.
Here's what I ended up doing:
% Set up an example table.
LastName = {'Smith';'Johnson';'Williams';'Jones';'Brown'};
Age = [38;43;38;40;49];
Height = [71;69;64;67;64];
Weight = [176;163;131;133;119];
BloodPressure = [124 93; 109 77; 125 83; 117 75; 122 80];
T = table(Age,Height,Weight,BloodPressure,'RowNames',LastName);
% Get the table in string form.
TString = evalc('disp(T)');
% Use TeX Markup for bold formatting and underscores.
TString = strrep(TString,'<strong>','\bf');
TString = strrep(TString,'</strong>','\rm');
TString = strrep(TString,'_','\_');
% Get a fixed-width font.
FixedWidth = get(0,'FixedWidthFontName');
% Output the table using the annotation command.
annotation(gcf,'Textbox','String',TString,'Interpreter','Tex','FontName',FixedWidth,'Units','Normalized','Position',[0 0 1 1]);

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeTables についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by