I have information like:
Coisas
X 3.16
Y 1.53
Z 0.000000Lat 0.000000Long
Cenas
X 275.30
Y 0.00
Z 142.43
K 0.000000 0.000000
T 43.734380 7.421440
How can I write this in a file.txt to apear like I have hear. I have already all the fprintf. But when I put to fid it stay different.
And this file need to be rewrite again, i will add info like that.
It´s like I open the file and write this and i close. then I want to open again e write more info. How can I do that. It dissapear all the previous info.
Thanks

 채택된 답변

Walter Roberson
Walter Roberson 2013년 12월 7일

0 개 추천

When you first create the file,
fid = fopen('Yourfile.txt', 'wt');
Each time you want to add something to it after having already closed it,
fid = fopen('Yourfile.txt', 'at');

댓글 수: 5

5mid
5mid 2013년 12월 7일
Yes it helps. But how can I put the text file in that structure. I appears all in one line.
Thanks
Walter Roberson
Walter Roberson 2013년 12월 7일
Are you forgetting to send the \n ?
fprintf(fid, 'line1\nline2\n')
Or did you miss the 't' part of the 'wt' and 'at' and you are opening the file through Notepad (not Notepad+) ?
5mid
5mid 2013년 12월 8일
I didn´t know that. I thought I could use \n on files too.
5mid
5mid 2013년 12월 8일
I found my problem.
Thanks
Walter Roberson
Walter Roberson 2013년 12월 8일
Yes, you use \n in files. But when you write something to a file and then close it, there is no \n automatically added: opening for append and writing something else would continue the exact same line.

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

추가 답변 (0개)

카테고리

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

질문:

2013년 12월 7일

댓글:

2013년 12월 8일

Community Treasure Hunt

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

Start Hunting!

Translated by