I have asked a related question in the past and I know how to read the file thanks to the help of the experts here. Now I have a new problem. I first read the data from the file like so:
fid = fopen('D:\file.txt', 'rt');
a = textscan(fid, '%s %f %f %f %f %f %f', ...
'Delimiter',',', 'CollectOutput',1, 'HeaderLines',1);
fclose(fid);
I then process the file and change a few values of the column. Now I want to write a new file newfile.txt
in the exact same format as my file.txt
with the new values. How do I do that?
If I do the following:
M = [datenum(a{1}) a{2}];
dlmwrite('newfile1.txt', M);
it gives me a new file without my first row of headers and without column 1 and column2 in the format I want.
My file format is given below:
date time, M01, M02, M03, M04, M05, M06
8/15/2009, 0:00:00, 5.8, 7.8, 7.8, 7.3, 0, 7.9
8/15/2009, 0:10:00, 7.1, 8.1, 8.1, 7.7, 0, 8.1
8/15/2009, 0:20:00, 6.8, 7.4, 7.6, 7.1, 0, 7.3
8/15/2009, 0:30:00, 5.6, 6.8, 7.1, 6.6, 0, 6.8
8/15/2009, 0:40:00, 3.9, 6.2, 6.4, 6.2, 0, 6.4
8/15/2009, 0:50:00, 4.6, 5.5, 6.1, 5.8, 0, 5.6
8/15/2009, 1:40:00, 7, 7, 7.2, 6.9, 0, 6.3
i am able to make a new file.txt in format
My file format is given below:
5.8, 7.8, 7.8, 7.3, 0, 7.9
7.1, 8.1, 8.1, 7.7, 0, 8.1
6.8, 7.4, 7.6, 7.1, 0, 7.3
5.6, 6.8, 7.1, 6.6, 0, 6.8
3.9, 6.2, 6.4, 6.2, 0, 6.4
4.6, 5.5, 6.1, 5.8, 0, 5.6
7, 7, 7.2, 6.9, 0, 6.3
Can some one help me 2 copy the headers and the first 2 columns into this new file?