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模式。