MATLAB爱好者论坛-LabFans.com

MATLAB爱好者论坛-LabFans.com (https://www.labfans.com/bbs/index.php)
-   资料存档 (https://www.labfans.com/bbs/forumdisplay.php?f=72)
-   -   如何以给定格式将数据保存到文本文件? (https://www.labfans.com/bbs/showthread.php?t=22687)

poster 2019-12-10 16:49

如何以给定格式将数据保存到文本文件?
 
我想将矩阵保存到文本文件,以便可以通过另一个程序读取它。现在,我使用:

save('output.txt', 'A','-ascii'); 但这会将我的文件另存为

6.7206983e+000 2.5896414e-001 6.5710723e+000 4.9800797e-00 6.3466334e+000 6.9721116e-001 5.9975062e+000 1.3346614e+000 6.0224439e+000 1.8127490e+000 6.3466334e+000 2.0517928e+000 6.3965087e+000 1.9721116e+000 但我想保存它们时不要使用“ e-notation”,而不是全部数字。是否有捷径可寻?

编辑:谢谢!那很好。抱歉,但是我认为我使用回滚弄乱了您的编辑。


回答:
我将使用[URL="https://www.mathworks.com/help/matlab/ref/fprintf.html"]fprintf[/URL]函数,该函数将允许您自己定义输出数据所用的格式。例如:

fid = fopen('output.txt', 'wt'); fprintf(fid,'%0.6f %0.6f\n', A.'); fclose(fid); 这将输出精度为小数点后6位的矩阵A。注意,您还必须使用函数[URL="https://www.mathworks.com/help/matlab/ref/fopen.html"]fopen[/URL]和[URL="https://www.mathworks.com/help/matlab/ref/fclose.html"]fclose[/URL] 。



[url=https://stackoverflow.com/questions/926741]更多&回答...[/url]


所有时间均为北京时间。现在的时间是 23:46

Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.