Displaying Tabular Data with heading in matlab
9 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Image Analyst
2015-1-25
Try this:
fprintf(' x-val, y-val, z-val\n')
fprintf('--------------------------------\n')
fprintf('%8.2f %10.1f %12.2f\n', table)
0 个评论
更多回答(1 个)
Geoff Hayes
2015-1-25
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 个评论
Image Analyst
2015-1-25
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!