How do I display a Table on Command Window?
Show older comments
Trying to display something like this:
Name A B C D
--------------------------------
Min 1 2 3 4
Max 5 6 7 8
Any Ideas?
1 Comment
Adam Danz
on 13 Apr 2021
@zaianb almahdi, are you having trouble displaying the table using disp(T)? Your comment is not clear.
Answers (1)
Here are two methods that produce that table. The first defines each column of the table. The second converts the matrix into a table.
% Method 1: Define each column
T = table([1;5],[2;6],[3;7],[4;8],'VariableNames',{'A','B','C','D'},'RowName',{'Min','Max'});
% Method 2: convert matrix
T = array2table([1:4;5:8],'VariableNames',{'A','B','C','D'},'RowName',{'Min','Max'});
% Display table
disp(T)
More info and practice:
10 Comments
HiWave
on 13 May 2023
If the table is too long this doesn't display.
Walter Roberson
on 13 May 2023
displayWholeObj(T, 'T')
The first T is the variable or expression containing the table. The 'T' is the name to print in
T =
the header
Adam Danz
on 13 May 2023
T = array2table(randi(9, 100, 2));
which displayWholeObj(T)
help @tabular/displayWholeObj
When you are using LiveScript, disp() displays a whole table in a scrolling region (or at least something more than 1000 lines). But if you are not using LiveScript, then disp() of a table displays only something like 100 lines and then gives you a link to click to display the entire table. That link uses displayWholeObj() to do the work. It isn't documented, but when it changes we will be able to read the replacement code out of the revised link ;-)
Adam Danz
on 15 May 2023
Michael Willig
on 30 Nov 2023
Genious !!! Many thanks @Walter Roberson
Peter Perkins
on 1 Dec 2023
You really don't want to use this function. "Do not use this function. Use disp instead." You have been warned.
"But if you are not using LiveScript, then disp() of a table displays only something like 100 lines and then gives you a link to click to display the entire table." A rare misstatement by Walter. That's what display does. Maybe I've misunderstood. disp shows the whole thing. The only extra thing displayWholeObj does is show the "t =" and the size/type, which is not what the OP asked for.
I don't understand this: "If the table is too long this [i.e. disp(T)] doesn't display."
Walter Roberson
on 1 Dec 2023
@Peter Perkins is right.
At least outside of LiveScript (which might have different results)
If you just name a table as an expression by itself, then that is internally a request to display(), and that will display only the first 24 and last 24 rows of the table, same as if you display() the table explicitly.
If you disp() the table then you will not get the header information about the table name and type and size, but the entire table will display.
displayWholeTable() will display the entire table and the name / type / size header.
Testing with MATLAB Answers (which should be the same as LiveScript)
I added comments about what I observe while in original composition mode. The saved message may show up differently; I will comment afterwards on any difference in the saved message.
T = array2table((1:123).');
fprintf('first trying with just variable name\n');
T
%Answers while composing: first 16 rows appeared then . . . and no scroll
fprintf('now trying with disp()\n');
disp(T)
%Answers while composing: first 12 rows visible, scroll to see rest
fprintf('now trying with display()\n');
display(T)
%Answers while composing: first 16 rows appeared then . . . and no scroll
fprintf('now trying with displayWholeObj\n');
displayWholeObj(T, 'T')
%Answers while composing: first 8 rows visible, scroll to see rest
fprintf('done\n');
Walter Roberson
on 1 Dec 2023
first trying with just variable name
Answers while viewing: first 10 rows appeared with a scroll that allowed seeing the first 16 rows and then . . .
now trying with disp()
Answers while viewing: first 11 rows appeared with a scroll that allowed seeing the entire table
now trying with display()
Answers while viewing: first 10 rows appeared with a scroll that allowed seeing the first 16 rows and then . . .
now trying with displayWholeObj
Answers while viewing: first 7 rows appeared with a scroll that allowed seeing the entire table
Categories
Find more on Numeric Types 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!