dlmwrite
用法:
dlmwrite(filename,M); %注意变量不要加引号
dlmwrite(filename,M,'-append'); %在文件末尾追加 dlmwrite(filename,M,delimiter); %采用delimiter分隔,默认分隔符为分号;dlmwrite(__,'newline','pc') %在txt文件中实现换行举例:
A=rand(3,4);dlmwrite('test.txt',A,'delimiter',',','precision',3) %precision保留三位有效数字type('test.txt')
Matlab命令行输出:
>> Untitled0.4018,0.1233,0.4173,0.94480.07597,0.1839,0.04965,0.49090.2399,0.24,0.9027,0.4893
打开txt文件显示:
没有实现换行。
采用下面实现txt文件换行:
dlmwrite('test.txt',A,'delimiter','\t','precision',3,'newline','pc')
打开txt文件显示:
参考:
save
用法:
save(filename,variables) %将变量保存到MAT文件中,注意变量要加引号'',变量可以有多个 save(filename,variables,'-ascii') %将变量保存在ascii文件中 save(filename,variables,'-ascii','-append') %追加到文件末尾,注意没有属性delimiter,precision
举例:
A=rand(3,4);save('test.txt','A','-ascii')type('test.txt')
打开txt文件:
参考: