append data...it doesnt change line
9 ビュー (過去 30 日間)
i want to open the 33.txt go to the end of the file add the number 4 ,change line and etc etc...
what is my error ? my code doesnt change line... thank you
Tom 2013 年 6 月 26 日
try adding a carriage return as well:
I'd also recommend using fclose(fid) each time you've finished with the file
Tom 2013 年 6 月 27 日
for what it's worth, Jan is correct about this being a Notepad issue - if you just use '\n' and open it within MATLAB, it appears on a new line.
その他の回答 (2 件)
Image Analyst 2013 年 6 月 26 日
Why is fopen inside the loop? You aren't showing all your real code but chances are that you want it before the loop, not inside it. Also, add an fclose after the loop.
Jan 2013 年 6 月 26 日
The data is written, when the file is closed:
fid = fopen('C:\Users\Mr Andrew\Desktop\33.txt', 'a');
for k = 1:5
fclose(fid); % close the file!
Jan 2013 年 6 月 27 日
編集済み: Jan 2013 年 6 月 27 日
The text file created by my program is correct and understood by almost all editors. Only Notepad fails, but this is a problem of Notepad, not of the file.
Bit inserting the \r explicitly causes traoubles under e.g. older versions of XEmacs, the TeX interpreter, Matlab until version 6.5 under Linux, etc. Therefore the most efficient solution is relying on '\n' and omitting the usage of the dull Notepad (Notepad++ from the net is much smarter!).
Another method to create the old DOS linebreaks under Windows: Open the file in text-mode:
Then fprintf(fid, '\n') writes \r\n autoamtically. But this can have strange side effects, like using the End-Of-File character accidently and the number of characters will differ from the number of bytes.
Find more on Text Files in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!