Export Sorted Columns to Existing File
Show older comments
Hello, I am running through ~50 text files and read them in order to sort the columns of the data, however the problem arises in the printing/exporting of the data. I would like to overwrite the files that I am reading in with the new, sorted data, and thus do not want to have to specify an output file. My current codes is as follows.... slopef = dir('*.out'); numfiles = length(slopef); mydata = cell(1, numfiles);
for k = 1:numfiles %fid=fopen(slopef(k).name,'a+'); fid=fopen(slopef(k).name,'w'); mydata{k} = load(slopef(k).name);
temp=sort(mydata{k});
ds=mat2dataset(temp,'VarNames',{'YYYY','MM','DD','TMIN','TMAX','RAIN'});
%export(ds,'File','Nolables.txt','WriteVarNames',false)
fprintf(fid,ds.TMIN)
%csvwrite('blah',temp)
fclose(fid);
end
Answers (1)
dpb
on 9 Oct 2013
Steps:
fopen for rw
read
sort
frewind
write
fclose
repeat 'til done...
Categories
Find more on Text Files in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!