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
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
Ted Weber 2017년 10월 27일
Thanks!

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

 채택된 답변

Ted Weber
Ted Weber 2017년 10월 27일

0 개 추천

Thanks for the help! I came to basically the same solution, before I saw Star Strider's response. I still don't really understand why I couldn't transpose the original vector, but I was able to get the table to look exactly how I wanted by doing this:
>> table=[A;x;y;z];
fprintf ('\t %7.1f \t %8.4f \t %9.4f \t \t %11.4f \n', table)
0.0 -0.0000 -0.0000 -0.0000
36.0 -0.2965 -0.1267 -0.2893
72.0 -0.5662 -0.4004 -0.5552
108.0 -0.7839 -0.6897 -0.7742
144.0 -0.9269 -0.9009 -0.9228
180.0 -0.9775 -0.9775 -0.9775
216.0 -0.9269 -0.9009 -0.9228
252.0 -0.7839 -0.6897 -0.7742
288.0 -0.5662 -0.4004 -0.5552
324.0 -0.2965 -0.1267 -0.2893
360.0 -0.0000 -0.0000 -0.0000

추가 답변 (1개)

Star Strider
Star Strider 2017년 10월 27일

1 개 추천

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
Ted Weber 2017년 10월 27일
Thanks!
Star Strider
Star Strider 2017년 10월 27일
My pleasure!
Diaa
Diaa 2019년 9월 7일
Could you please explain why the first vector didn't get transposed?

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

카테고리

도움말 센터File Exchange에서 Tables에 대해 자세히 알아보기

질문:

2017년 10월 27일

댓글:

2019년 9월 7일

Community Treasure Hunt

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

Start Hunting!

Translated by