1、
save filename dataarray -ASCII
>> A=rand(3,4);
>> save savetxt.txt A -ASCII
>> A
A =
0.8147 0.9134 0.2785 0.9649
0.9058 0.6324 0.5469 0.1576
0.1270 0.0975 0.9575 0.9706
savetxt.txt:
8.1472369e-01 9.1337586e-01 2.7849822e-01 9.6488854e-01
9.0579194e-01 6.3235925e-01 5.4688152e-01 1.5761308e-01
1.2698682e-01 9.7540405e-02 9.5750684e-01 9.7059278e-01
2、
dlmwrite(filename,M,'D')
filename为待写入数据的文件名
M为写入到文件中的数值阵列
'D'为元素之间的分隔符
>> A=rand(3,4);
>> dlmwrite('mydata.txt',A,';');
'mydata.txt':
0.95717;0.14189;0.79221;0.035712
0.48538;0.42176;0.95949;0.84913
0.80028;0.91574;0.65574;0.93399
>> dlmwrite('mydata.txt',A,'newline','pc');
0.95717,0.14189,0.79221,0.035712
0.48538,0.42176,0.95949,0.84913
0.80028,0.91574,0.65574,0.93399
3、
fprintf(fileID,format,A,.....)
fprintf(fileID,A)
count=fprintf(fileID,format,A)
count为字节数,fprintf函数向fileID标示的文件中写入的字节数