如何打印数组在Matlab .txt文件? [英] How to print an array to a .txt file in Matlab?
本文介绍了如何打印数组在Matlab .txt文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我刚开始学习的 Matlab的,所以这个问题可能是很基本的:
我有一个变量
A = [2.3 3.422 -6.121 9 4.55]
我想要的值输出到像这样的.txt文件:
2.3
3.422
-6.121
9
4.55
我怎样才能做到这一点?
FID =的fopen('C:\\\\ coeffs.txt','W'); //这个打开文件
//现在如何打印A到文件?
解决方案
下面应该做的伎俩:
FID =的fopen('C:\\\\ coeffs.txt','重'); %注意'重量'在文本模式下写
fprintf中(FID,'%F \\ N',一个); %的格式串被施加到的一个的每个元素
FCLOSE(FID);
有关更多信息,检查出 FOPEN 和<一个文档HREF =http://www.mathworks.com/access/helpdesk/help/techdoc/ref/fprintf.html> fprintf中。
I am just beginning to learn Matlab, so this question might be very basic:
I have a variable
a=[2.3 3.422 -6.121 9 4.55]
I want the values to be output to a .txt file like this:
2.3
3.422
-6.121
9
4.55
How can I do this?
fid = fopen('c:\\coeffs.txt','w'); //this opens the file
//now how to print 'a' to the file??
解决方案
The following should do the trick:
fid = fopen('c:\\coeffs.txt','wt'); % Note the 'wt' for writing in text mode
fprintf(fid,'%f\n',a); % The format string is applied to each element of a
fclose(fid);
For more info, check out the documentation for FOPEN and FPRINTF.
这篇关于如何打印数组在Matlab .txt文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文