Good morning\evening
I tried to print a result matrix R in an output file.
fprintf(fid,'%.3f\t\n %.3f\t\n %.3f\t\n',R);
Actually, the output prints the matrix row by row.
Can you help me?
Regards, Ayda

 채택된 답변

Walter Roberson
Walter Roberson 2011년 10월 31일

0 개 추천

Each of the \n in the formats indicates that you want to start a new line.
The \t you have indicate that you want a tab before the newline; that would be somewhat unusual.
Anyhow, you should use R.' (the transpose of R) as the argument to fprintf() instead of just R

댓글 수: 3

Ayda
Ayda 2011년 10월 31일
Thanks Mr. Walter for answering
but am still confuse ..
where i should but \n
I tried
fprintf(fid,'%.2f %.2f %.2f\n',R');
but it did not work
Walter Roberson
Walter Roberson 2011년 10월 31일
What size is your array R, and how do you want it to look when it is printed out?
I note that you used R' rather than the R.' that I indicated. The effect is the same for real-valued matrices, but if your R happened to contain complex values then using R' would lead to incorrect printout, as R' means the "conjugate transpose" (that is, the result is the transpose of the result of taking the complex conjugate of each item.)
The format you have given would be suitable for a matrix R which is 3 columns wide and you want two decimal places of each value printed out. The output would, though, appear "ragged" such as
11.23 49.18 28.20
5.36 33.62 -1.98
as you have not requested that a fixed number of characters be used per column.
Ayda
Ayda 2011년 10월 31일
sorry i did not notice that you say .'
Thanks alot
its works =)

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

추가 답변 (0개)

카테고리

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

태그

질문:

2011년 10월 31일

Community Treasure Hunt

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

Start Hunting!

Translated by