Delete empty line in .dat file.

5 ビュー (過去 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 Center および File ExchangeGet 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