MATLAB如何在文本文件中写入标题 [英] MATLAB how to write header in text file

查看:18
本文介绍了MATLAB如何在文本文件中写入标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在文本文件中写入文本标题?例如在下面的例子中,如何只写一次标题code Salay Month?

How to write a text header in text file? for example in the example below, how to write the header code salay month just once?

Code Salary Month
12   1000   12
14   1020   11
11   1212   9 

代码:

fid = fopen('analysis1.txt','wt');
for i=1:10
   array = []; % empty the array
   ....
   array = [code salary month];
   format short g;
   fprintf(fid,'%g	 %g	 %g
',array); % write to file
end
fclose(fid);

推荐答案

有什么理由不用像下面这样简单的解决方案吗?

Is there any reason for not using simple solution like following?

...
fid = fopen('analysis1.txt','wt');
fprintf(fid, '%s	 %s	 %s
', 'Code','Salary','Month');
for i=1:10
   array = []; % empty the array
...

这篇关于MATLAB如何在文本文件中写入标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆