MATLAB Answers

Give title for Table

518 ビュー (過去 30 日間)
Elysi Cochin
Elysi Cochin 2021 年 5 月 2 日
コメント済み: Elysi Cochin 2021 年 5 月 3 日
Is it possible to give title for a table i have displayed as below
If i wanted to give a title 'My Table', how to give it?
Details = [38,71,176,124,93;...
43,69,163,109,77;...
38,64,131,125,83;...
40,67,133,117,75;...
49,64,119,122,80];
T = array2table(Details,...
'VariableNames',{'Age' 'Height' 'Weight' 'BP_High' 'BP_Low'},...
'RowNames',{'Smith';'Johnson';'Williams';'Jones';'Brown'});
disp(T)

採用された回答

Adam Danz
Adam Danz 2021 年 5 月 3 日
編集済み: Adam Danz 2021 年 5 月 3 日
You could effectively give a title to a table by nesting the table within another single-column table that contains the title.
Details = [38,71,176,124,93;...
43,69,163,109,77;...
38,64,131,125,83;...
40,67,133,117,75;...
49,64,119,122,80];
T = array2table(Details,...
'VariableNames',{'Age' 'Height' 'Weight' 'BP_High' 'BP_Low'},...
'RowNames',{'Smith';'Johnson';'Williams';'Jones';'Brown'});
T = table(T,'VariableNames',{'My Table'}); % Nested table
disp(T)
My Table Age Height Weight BP_High BP_Low ________________________________________________________ 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
However, now you'll have to index the table differently. For example, to access Height,
T.('My Table').Height
Or to access the 3rd row,
T.('My Table')(3,:)
or you could un-nest the table,
T = T.('My Table');
  5 件のコメント
Elysi Cochin
Elysi Cochin 2021 年 5 月 3 日
Yes sir, that is a better and simple option in my case, as i just need to display. Thank you sir

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

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2021 年 5 月 3 日
No, table() is designed for programming, not for display purposes.
  3 件のコメント
Elysi Cochin
Elysi Cochin 2021 年 5 月 3 日
Thank you so much for the detailed explaination

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by