Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays 如何在Matlab中将数组打印为.txt文件?_Arrays_Matlab_File Io_Text Files - Fatal编程技术网

Arrays 如何在Matlab中将数组打印为.txt文件?

Arrays 如何在Matlab中将数组打印为.txt文件?,arrays,matlab,file-io,text-files,Arrays,Matlab,File Io,Text Files,我刚刚开始学习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'); //this opens the file //now how to print 'a' to the file?? 下面应该可以做到这一点: fid = fopen('c:\\coeffs.tx

我刚刚开始学习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'); //this opens the file
//now how to print 'a' to the file??

下面应该可以做到这一点:

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);

有关更多信息,请查看和的文档。

@gnovice是的,确实如此。谢谢你知道有什么地方我可以找到像这样的基本资料吗。这是因为我刚开始使用Matlab,我经常发现自己被这些琐碎的东西困住了。我想我需要一个循环。不知怎的,所有的值都是自己打印出来的@eSKay:我为相关函数添加了几个链接。一般来说,MATLAB有非常好的文档和示例/教程,包括版本和在线MathWorks网站()。在命令窗口中,HELP命令()通常非常有用@gnovice在输入中得到不正确的结果,作为单独的问题发布,因为它需要矩阵的格式,可以使用dlmwrite,例如,如果是矩阵,则可以使用以下方式保存:dlmwrite('file.txt',a)