Add a title to a table built with syntax - AUCtable = table(x, y, z)

I have built a table
AUCtable = table(x, y, z)
how do I print it out 'nicely' -- without getting ans = lots of information type of syntax??
display(AUCtable) and AUCtable prints out
AUCtable
2 new lines
numRows x numCols table
2 new lines
then the table
I could probably live with that -- if I could add a title -- and AUCtable.Properties.Description ='My title' does not work
Thanks

 Accepted Answer

I am not exactly certain what you want as the end result.
Try this:
x = rand(5,1); % Create Vector
y = rand(5,1); % Create Vector
z = rand(5,1); % Create Vector
T1 = table(x,y,z); % Create Original Table
T2 = table(T1, 'VariableNames',{'My Title'}); % Create ‘Super Table’
get_x = T2.('My Title').x; % Retrieve Sample Data
producing:
T2 =
5×1 table
My Title
x y z
______________________________
0.25515 0.9368 0.00665
0.16694 0.77852 0.8626
0.19633 0.59893 0.011251
0.60822 0.5609 0.95496
0.59116 0.83691 0.97722
And of course:
disp(T2)
also works, producing simply:
My Title
x y z
_______________________________
0.053157 0.68624 0.20949
0.66566 0.39679 0.37425
0.5316 0.019607 0.31304
0.44307 0.53647 0.84004
0.28418 0.883 0.24669
.

7 Comments

Nice try -- Your code works
However I get "My title" followed by 20 copies of [1×6 table]
-- I think because two of my columns are not numbers
Not clear what the problem is
as y = [false false false true true] ' and y = ['2' '2' '2' '2' '2']'; both work
WIll try to find out if I have a hidden non-printing character in there
Thank you!
I cannot experiment with your table.
Perhaps something like:
T = T(1,1:6)
would eliminate the duplicates.
I think I gone -- one-hack-too-far -- to get a little more speed rather than write a for loop <SMILE>
One of my variables is essentially this
y = repmat(' ',5, 1);
But using that syntax in your code works -- so I am probably doing something I am not recognizing I am doing
Time to walk away and have a beer -- and try in an hour
Thanks for your help
it is a matlab thing
This code makes T2 fail
x1 = x; y1 = y; z1 = z;
T1 = table(x, y, z, x1, y1, x1)
T2 = table(T1, 'VariableNames',{'My Title'}); ;
disp(T2)
No, T2 is not broken: you are just encountering a limitation on display of a table, that for numeric variables only 5 columns might be displayed (actual number of columns might depend upon the width of your command window.)
x = rand(5,1); % Create Vector
y = rand(5,1); % Create Vector
z = rand(5,1); % Create Vector
x1 = x; y1 = y; z1 = z;
T1 = table(x, y, z, x1, y1, x1)
T1 = 5x6 table
x y z x1 y1 x1_1 ________ ________ ________ ________ ________ ________ 0.061799 0.21369 0.20443 0.061799 0.21369 0.061799 0.044648 0.88702 0.19611 0.044648 0.88702 0.044648 0.70321 0.9444 0.17765 0.70321 0.9444 0.70321 0.39153 0.76507 0.72502 0.39153 0.76507 0.39153 0.46799 0.054191 0.091939 0.46799 0.054191 0.46799
T2 = table(T1, 'VariableNames',{'My Title'});
disp(T2)
My Title ___________ [1x6 table] [1x6 table] [1x6 table] [1x6 table] [1x6 table]
T1_5 = T1(:,1:5);
T2_b = table(T1_5, 'VariableNames', {'My Title'});
disp(T2_b)
My Title x y z x1 y1 ________________________________________________________ 0.061799 0.21369 0.20443 0.061799 0.21369 0.044648 0.88702 0.19611 0.044648 0.88702 0.70321 0.9444 0.17765 0.70321 0.9444 0.39153 0.76507 0.72502 0.39153 0.76507 0.46799 0.054191 0.091939 0.46799 0.054191
I am not certain what the problem is (or was). I submitted an enhancement request asking that (1) the six-column table displays as it should, with the title displayed above the variable names as it does with the three-column table, and (2) that adding the option of a table title would be an interesting addition.
So while ‘T2’ does not display as you (or I) would like it to (all six columns with their variable names),
get_x = T2.('My Title').x; % Retrieve Sample Data
continues to work correctly, so all is not lost.
This was an interesting problem!
Thanks Walter -- I meant fail to display as I want -- rather than fail /crash

Sign in to comment.

More Answers (1)

disp(AUTtable) -- and answered my own first question by mistake <GROAN>
Adding a title still defeats me

Products

Release

R2020a

Asked:

on 9 Mar 2021

Commented:

on 9 Mar 2021

Community Treasure Hunt

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

Start Hunting!