Matlab------------导出数据

1.用fprintf 函数写数据到txt,xls

Example:

x = 0:.1:1;
y = [x; exp(x)];
fid = fopen('exp.txt', 'w');
fprintf(fid, '%6.2f %12.8f\n', y);
fclose(fid)

tip:执行上述代码执行,肯定不会换行的,换行的问题试一下下面的代码

x = 0:.1:1;
y = [x; exp(x)];
fid = fopen('exp.txt', 'wt');
fprintf(fid, '%6.2f %12.8f\n', y);
fclose(fid);


fid = fopen('x.txt', 'wt');
fprintf(fid, '%6.2f \n', x);
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, followed
by the letter t, for example 'rt' or 'wt+. On UNIX® systems, text and binary mode
 are the same. (UNIX is a registered trademark of The
Open Group in the United States and other countries).

就是有两种读取模式binary or text. When choosing the binary model,No characters are 
given special treatment. 所以我们选择要注明text模式。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值