Print a table with 4 columns fprintf
조회 수: 13 (최근 30일)
이전 댓글 표시
95.0000 1.8700 10.9831 8.9874
2.0000 45.0000 1.6000 7.1402
3.0000 76.0000 1.7000 9.3224
4.0000 88.0000 1.6100 9.5381
5.0000 55.0000 1.5000 7.4204
6.0000 50.0000 1.6100 7.5010
7.0000 61.0000 1.5800 8.0519
8.0000 105.0000 1.8300 11.2821
I specify the vectors like this: N=[1,2,3,4,5,6,7,8]; and I use fprintf(fileID,'%5.2f\n\' but if i repeat this for my other variable it all ends up in one column?How to get it in 4 columns
댓글 수: 0
답변 (2개)
Stephen23
2017년 3월 31일
편집: Stephen23
2017년 3월 31일
When you put all of the data into one matrix then your task is easy:
>> M = [95, 1, 10.9831, 8.9874;...
2, 45, 1.6000, 7.1402;...
3, 76, 1.7000, 9.3224;...
4, 88, 1.6100, 9.5381;...
5, 55, 1.5000, 7.4204;...
6, 50, 1.6100, 7.5010;...
7, 61, 1.5800, 8.0519;...
8, 105, 1.8300, 11.2821];
>> fmt = '%3d,%4d,%6.2f,%6.2f\n';
>> fprintf(fmt,M.')
95, 1, 10.98, 8.99
2, 45, 1.60, 7.14
3, 76, 1.70, 9.32
4, 88, 1.61, 9.54
5, 55, 1.50, 7.42
6, 50, 1.61, 7.50
7, 61, 1.58, 8.05
8, 105, 1.83, 11.28
Note that I specified different formats for each column, and used transpose M.' instead of the linear algebra operation ctranspose M'.
댓글 수: 0
참고 항목
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!