Displaying Tabular Data with heading in matlab
35 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Chuzymatics Chuzymatics
il 25 Gen 2015
Risposto: Image Analyst
il 25 Gen 2015
Dear All, I intend to display result of my calculation in a way that each column will have a heading in the command window. I want x values neatly displayed under x-val; y values under y-val etc; thanks if you can help. Here is my code:
x =1:20;
y= x.^2;
z = x*20;
table =[x; y; z];
disp('Table shows table values')
disp('x-val, y-val, z-val')
fprintf('%8.2f %10.1f %12.2f\n', table)
0 Commenti
Risposta accettata
Image Analyst
il 25 Gen 2015
Try this:
fprintf(' x-val, y-val, z-val\n')
fprintf('--------------------------------\n')
fprintf('%8.2f %10.1f %12.2f\n', table)
0 Commenti
Più risposte (1)
Geoff Hayes
il 25 Gen 2015
Chuzymatics - depending upon your version of MATLAB (I think from R2013b and above) why not try and use the table function? Something like the following may work
T = table(x',y',z','VariableNames',{'xval','yval','zval'})
which creates a table as
T =
xval yval zval
____ ____ ____
1 1 20
2 4 40
3 9 60
4 16 80
5 25 100
6 36 120
7 49 140
8 64 160
9 81 180
10 100 200
11 121 220
12 144 240
13 169 260
14 196 280
15 225 300
16 256 320
17 289 340
18 324 360
19 361 380
20 400 400
Note that the inputs to table are columns (that is why there is a transpose for each input variable) and the names of each variable (or columns names) is specified in the array of strings (note that these names must be valid MATLAB variable names, that is why I removed the dash from each).
Try the above and see what happens!
2 Commenti
Image Analyst
il 25 Gen 2015
Why does your code include Geoff's table() function which you admit you don't have since you have an antique version of MATLAB? You can't use table like that. Your table is a simple numerical matrix.
Vedere anche
Categorie
Scopri di più su Logical in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!