Delete empty line in .dat file.

조회 수: 3 (최근 30일)
Hammad
Hammad 2019년 10월 3일
댓글: Hammad 2019년 10월 3일
I have to import .dat file into matlab and there are thousands of empty lines (as shown in the attaced picture). I need to delete these lines.Annotation 2019-10-04 030249.png

채택된 답변

Walter Roberson
Walter Roberson 2019년 10월 3일
filename = 'onetwo.dat';
outfilename = 'onetwo_slim.dat';
%read the content of the existing file
S = fileread(filename);
%remove extra sequential line terminators
SS = regexprep(S, '(\r?\n)(\r?\n)*', '$1');
%write a new file from the result
fid = fopen(outfilename, 'w');
fwrite(fid, SS);
fclose(fid);
  댓글 수: 1
Hammad
Hammad 2019년 10월 3일
this worked, thank you!!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by