フィルターのクリア

how to delete header and footer from dat. file?

5 ビュー (過去 30 日間)
Mainul Hoque
Mainul Hoque 2014 年 10 月 30 日
コメント済み: Mainul Hoque 2014 年 11 月 4 日
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

採用された回答

Orion
Orion 2014 年 10 月 30 日
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 件のコメント
Mainul Hoque
Mainul Hoque 2014 年 11 月 4 日
Hi Orion,
Thank you very much for your answer. It's really helpful and work very well.
Cheers!!!!
Mainul

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by