MATLAB how to write header in text file

梦想的初衷 提交于 2019-11-29 11:23:27

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

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

Just to make it easy to copy and paste

fid = fopen('Output.txt','wt');
fprintf(fid, '%s\t %s\t %s\n', 'x','y1','y2');
% have a matrix M(N,3) ready to go
dlmwrite('Output.txt', M,'delimiter', '\t', '-append')
fclose(fid);

Jaap

Sami

Thanks, Here is a script I modified to generate one variable file,

fid = fopen('vout.h','wt');
format short g;

fprintf(fid,' /* Header File for the variable vout */  \n\n' );

fprintf(fid,'int vout[ %g ] = { ' ,length(vout));

for i=1:length(vout)

   fprintf(fid,'%g,',vout(i)); % write to file
end
fprintf(fid,'} ; ');

fclose(fid);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!