Write to txt, delimited by char(10)
8 次查看(过去 30 天)
显示 更早的评论
Let
x = ['a' char(10) 'b'];
How can I print this to a text file say, test.txt, in such a way that it reads a in the first line and b in the second one?
0 个评论
采纳的回答
GT
2018-12-11
x = ['a' char(10) 'b'];
fp = fopen('test.txt','w');
fwrite(fp,x);
fclose(fp);
I am on a Mac and using R2018b. That being said the above should work on all OS and most MATLAB releases.
There is also a command in MATLAB called newline (which is the same as char(10)
4 个评论
GT
2018-12-11
This has to do with your OS, and editor and how it interprets new lines.
char(10)
char(13)
Sometimes you would need both a \r\n for editors to recognize newline.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Text Files 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!