Displaying Tabular Data with heading in matlab
조회 수: 10 (최근 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!