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

发布于 2024-08-05 04:33:29 字数 342 浏览 3 评论 0原文

我刚刚开始学习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??

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??

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

抽个烟儿 2024-08-12 04:33:29

以下应该可以解决问题:

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

有关详细信息,请查看 FOPENFPRINTF

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文