Azzera filtri
Azzera filtri

how to delete header and footer from dat. file?

5 visualizzazioni (ultimi 30 giorni)
Hi!
I have 5000 dat. file. Each file have 3 header and 3 footer. I need to delete header and footer from each file and then save it again as dat. file.
Can anybody kindly tell me what is the procedure.
Regards
Mainul

Risposta accettata

Orion
Orion il 30 Ott 2014
Hi,
i guess you need more or less this kind of code :
for i = 1:5000
FileToRewrite = ['DatFile_' num2str(i) '.dat'];
% phase 1 : read the ith dat file
fid = fopen(FileToRewrite,'r');
TextDat = textscan(fid,'%s','delimiter','\n');
fclose(fid);
% phase 2 : just take from the 4th line (3 headers) until the end-3
% (3 footers)
NewTextDat = TextDat{1}(3+1:end-3);
% phase 3 : rewrite the file with the new data
fid = fopen(FileToRewrite,'wt');
fprintf(fid,'%s\n',NewTextDat{:});
fclose(fid);
end
Big Warning : once you run this code, all you .dat files will be rewritten. think to make copies of your originals, in case there is a bug.
  1 Commento
Mainul Hoque
Mainul Hoque il 4 Nov 2014
Hi Orion,
Thank you very much for your answer. It's really helpful and work very well.
Cheers!!!!
Mainul

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Get Started with MATLAB in Help Center e File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by