How do I display a Table on Command Window?

397 visualizzazioni (ultimi 30 giorni)
Yao Chong Chow
Yao Chong Chow il 22 Gen 2020
Trying to display something like this:
Name A B C D
--------------------------------
Min 1 2 3 4
Max 5 6 7 8
Any Ideas?
  1 Commento
Adam Danz
Adam Danz il 13 Apr 2021
@zaianb almahdi, are you having trouble displaying the table using disp(T)? Your comment is not clear.

Accedi per commentare.

Risposte (1)

Adam Danz
Adam Danz il 22 Gen 2020
Modificato: Adam Danz il 24 Gen 2020
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)
A B C D _ _ _ _ Min 1 2 3 4 Max 5 6 7 8
More info and practice:
  10 Commenti
Walter Roberson
Walter Roberson il 1 Dic 2023
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');
first trying with just variable name
T
T = 123×1 table
Var1 ____ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
%Answers while composing: first 16 rows appeared then . . . and no scroll
fprintf('now trying with disp()\n');
now trying with disp()
disp(T)
Var1 ____ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
%Answers while composing: first 12 rows visible, scroll to see rest
fprintf('now trying with display()\n');
now trying with display()
display(T)
T = 123×1 table
Var1 ____ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
%Answers while composing: first 16 rows appeared then . . . and no scroll
fprintf('now trying with displayWholeObj\n');
now trying with displayWholeObj
displayWholeObj(T, 'T')
T = 123×1 table Var1 ____ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
%Answers while composing: first 8 rows visible, scroll to see rest
fprintf('done\n');
done
Walter Roberson
Walter Roberson il 1 Dic 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

Accedi per commentare.

Categorie

Scopri di più su Numeric Types in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by