Print a table with 4 columns fprintf

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

답변 (2개)

KSSV
KSSV 2017년 3월 31일

0 개 추천

A = magic(5) ;
fprintf([repmat('%f\t', 1, size(A, 2)) '\n'], A')

댓글 수: 1

Stephen23
Stephen23 2017년 3월 31일
Note that transpose A.' should be used, and not conjugate transpose A'.

댓글을 달려면 로그인하십시오.

Stephen23
Stephen23 2017년 3월 31일
편집: Stephen23 2017년 3월 31일

0 개 추천

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'.

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

제품

태그

질문:

2017년 3월 31일

편집:

2017년 3월 31일

Community Treasure Hunt

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

Start Hunting!

Translated by