views:

55

answers:

1

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\t %g\t %g\n',array); % write to file
end
fclose(fid);
+2  A: 

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
...
pepiino
Or write the header line as you suggest @pepiino, then use dlmwrite to append the table of data in one statement.
High Performance Mark
Thank you :-)..
Jessy