Printing to text file
2 次查看(过去 30 天)
显示 更早的评论
Pretty simple. I want to print this to a text file:
4
1
2
3
4
but instead I am getting this:
41234
Here's my code:
z = 4;
fid = fopen([mnl_data_path, 'packages.txt'], 'w');
a = num2str(z);
fprintf(fid,'%s\n',a);
for j = 1:1:z
a = num2str(j);
fprintf(fid,'%s\n',a);
end
fclose(fid);
Why isn't it printing to a new line?
0 个评论
回答(4 个)
the cyclist
2012-8-25
Strange. I get each digit on a separate line, as you intend.
I am using the prerelease of R2012b, on a Mac running OSX 10.6.8.
0 个评论
Edward Umpfenbach
2012-8-26
2 个评论
Image Analyst
2012-8-27
Try wordpad. I think wordpad and notepad behave differently with regards to how they interpret \n and \r\n. You can know for sure what's there if you have access to an editor that can view in hex format.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Text Data Preparation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!