Trouble with fprinft and transpose.
이전 댓글 표시
I'm new to MATLAB and coding and I could use some help. I have four row vectors. I want to make a table with four columns. The first variable won't transpose to column with fprintf, why?
>> fprintf ('\t%.1f %7.4f %7.4f %10.4f \n', A', x', y', z')
0.0 36.0000 72.0000 108.0000
144.0 180.0000 216.0000 252.0000
288.0 324.0000 360.0000 -0.0000
-0.3 -0.5662 -0.7839 -0.9269
-1.0 -0.9269 -0.7839 -0.5662
-0.3 -0.0000 -0.0000 -0.1267
-0.4 -0.6897 -0.9009 -0.9775
-0.9 -0.6897 -0.4004 -0.1267
-0.0 -0.0000 -0.2893 -0.5552
-0.8 -0.9228 -0.9775 -0.9228
-0.8 -0.5552 -0.2893 -0.0000
Here are my variables: >> A,x,y,z
A =
0 36 72 108 144 180 216 252 288 324 360
x =
0 -0.2965 -0.5662 -0.7839 -0.9269 -0.9775 -0.9269 -0.7839 -0.5662 -0.2965 0
y =
0 -0.1267 -0.4004 -0.6897 -0.9009 -0.9775 -0.9009 -0.6897 -0.4004 -0.1267 0
z =
0 -0.2893 -0.5552 -0.7742 -0.9228 -0.9775 -0.9228 -0.7742 -0.5552 -0.2893 0
댓글 수: 2
per isakson
2017년 10월 27일
See my function tprintf, tprintf writes tabular data to a text file. The answer is under the tab, Examples.
Ted Weber
2017년 10월 27일
채택된 답변
추가 답변 (1개)
Star Strider
2017년 10월 27일
Since all your variables are row vectors, try this:
fprintf ('\t%5.1f %7.4f %7.4f %10.4f \n', [A; x; y; z])
It should give you the result you want.
댓글 수: 3
Ted Weber
2017년 10월 27일
Star Strider
2017년 10월 27일
My pleasure!
Diaa
2019년 9월 7일
Could you please explain why the first vector didn't get transposed?
카테고리
도움말 센터 및 File Exchange에서 Tables에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!