Matlab将数据存为文本文件

dlmwrite :将一个矩阵写到由分隔符分割的文件中。
在保存整数到文件时使用save存为ascii文件时,常常是文件里都是实型格式的数据(有小数点,和后面很多的0,看着很不方便)。于是要保存此类数据时,我们可以使用此dlmwrite命令。
使用方法:
dlmwrite('filename', M)
使用默认分隔符“,”将矩阵M写入文本文件filename中;
dlmwrite('filename', M, 'D')
使用分隔符D分割数据,“ ”表示tab分割,“,”为默认分割符;
dlmwrite('filename', M, 'D', R, C)
从矩阵M的第R行、第C列开始,作为要写矩阵块的左上角,将数据用D分割写入文件。
其他用法有:
dlmwrite('filename', M, 'attrib1', value1, 'attrib2', value2, ...)
dlmwrite('filename', M, '-append')
dlmwrite('filename', M, '-append', attribute-value list)
例如:
a = [1 2 3; 4 5 6; 7 8 9];
dlmwrite('test.txt', a);
则test.txt中的内容为:
1,2,3
4,5,6
7,8,9
而使用save
a = [1 2 3; 4 5 6; 7 8 9];
save 'tst.txt' a -ascii;
文本文件里的内容为:
   1.0000000e+000   2.0000000e+000   3.0000000e+000
   4.0000000e+000   5.0000000e+000   6.0000000e+000
   7.0000000e+000   8.0000000e+000   9.0000000e+000
原文地址:https://www.cnblogs.com/lakeone/p/4072934.html