Export Sorted Columns to Existing File
Mostrar comentarios más antiguos
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
Respuestas (1)
dpb
el 9 de Oct. de 2013
Steps:
fopen for rw
read
sort
frewind
write
fclose
repeat 'til done...
Categorías
Más información sobre Text Files en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!