(1)保存为固定名称文件: save 路径\a.txt -ascii a
>> a=[1,2,3;4,5,6];
>> save C:\Users\Administrator\Desktop\a.txt -ascii a
(2)保存为变量名称文件:filename=['路径\',num2str(b),'.txt'];
save(filename,'a','-ascii');
a=[1,2,3;4,5,6];
filename=['C:\Users\Administrator\Desktop\',num2str(i),'.txt'];
>> for i=1:1:2
save(filename,'a','-ascii');
end
注:数据以指数形式保存
(1)保存为固定名称文件:dlmwrite('路径\a.txt',a,'delimiter','\t','newline','pc');
a=[1,2,3;5,7,9];
>>dlmwrite('C:\Users\Administrator\Desktop\matlab\a.txt',a,'delimiter','\t','newline','pc');
(2)保存为变量名称文件:filename=['路径\',num2str(b),'.txt']; dlmwrite(filename,a,'delimiter','\t','newline','pc');
a=[1,2,3;5,7,9];
>> for b=1:3
filename=['C:\Users\Administrator\Desktop\',num2str(b),'.txt'];
dlmwrite(filename,a,'delimiter','\t','newline','pc');
end
注:dlmwrite的详细用法参考: 点击打开链接
结果显示:
fopen----将数据按照指定格式读入到matlab中
fprintf--将数据按照指定格式写入到文本文件中
fclose---将文本文件关闭,结束操作
注:具体用法参考点击打开链接