Delete empty line in .dat file.

20 vues (au cours des 30 derniers jours)
Hammad
Hammad le 3 Oct 2019
Commenté : Hammad le 3 Oct 2019
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

Réponse acceptée

Walter Roberson
Walter Roberson le 3 Oct 2019
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 commentaire
Hammad
Hammad le 3 Oct 2019
this worked, thank you!!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Get Started with MATLAB dans Help Center et File Exchange

Produits


Version

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by