필터 지우기
필터 지우기

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 CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by