I have the following code and what ever I do, I m not able to print the two vectors as columns side by side. Please help.
A = [1;2;3];
B= [4;5;6];
fid = fopen('Myfiles.txt', 'w');
fprintf(fid, '%u %u \n', [A B]');
fclose(fid);
It prints as
1 4 2 5 3 6
But I want it as
1 4
2 5
3 6
Where am I going wrong? Thanks for your help.

 채택된 답변

Image Analyst
Image Analyst 2015년 10월 26일

0 개 추천

For me it doesn't. It works just fine:
A = [1;2;3]
B = [4;5;6]
fid = fopen('Myfiles.txt', 'w');
fprintf(fid, '%u %u \n', [A B]');
% sprintf('%u %u \n', [A B]')
fclose(fid);
type 'Myfiles.txt'
%delete('Myfiles.txt');
The type statement writes it out the command window and it looks just fine. If it doesn't for you, then, in fopen(), try using 'wt' instead of 'w' and see if that makes it look better.

댓글 수: 1

Nalini Nadupalli
Nalini Nadupalli 2015년 10월 26일
Yes it works... Thank you very much. It is of great help. What is the difference between 'wt' and 'w' ?

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

추가 답변 (0개)

카테고리

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

태그

질문:

2015년 10월 26일

댓글:

2015년 10월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by