matlab txt 换行,matlab的fprintf 函数写数据时换行的问题
Example:x = 0:.1:1;y = [x; exp(x)];fid = fopen('exp.txt', 'w');fprintf(fid, '%6.2f %12.8f\n', y);fclose(fid)把这个代码执行一下,可能不会换行的,那再试一下下面的代码x = 0:.1:1;y = [x; exp(x)];fid = fopen('exp.txt', 'wt');fprintf(
Example:
x = 0:.1:1;
y = [x; exp(x)];
fid = fopen('exp.txt', 'w');
fprintf(fid, '%6.2f %12.8f\n', y);
fclose(fid)
把这个代码执行一下,可能不会换行的,那再试一下下面的代码
x = 0:.1:1;
y = [x; exp(x)];
fid = fopen('exp.txt', 'wt');
fprintf(fid, '%6.2f %12.8f\n', y);
fclose(fid)
这次就没有问题了,我们要注意fopne的参数wt 而不是 w,这是matlab的在线帮助的东东fid = fopen(filename, permission_tmode) on Windows systems, opens the file in text mode instead of binary mode (the default). The permission_tmode argument consists of any of the specifiers shown in the Permission Specifiers table above, followedby the letter t, for example 'rt' or 'wt+. On UNIX® systems, text and binary mode are the same. (UNIX is a registered trademark of TheOpen Group in the United States and other countries).就是有两种读取模式binary or text. When choosing the binary model,No characters are given special treatment. 所以我们选择要注明text模式。
另外,对于dlmwrite可用:
dlmwrite(filename, net, '-append', 'delimiter', '\t', 'precision', 6, 'newline', 'pc');
【天涯博客】本文地址http://blog.tianya.cn/blogger/post_show.asp?BlogID=30634&PostID=15209386
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐


所有评论(0)