Delete empty line in .dat file.
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hammad
am 3 Okt. 2019
Kommentiert: Hammad
am 3 Okt. 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.

0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 3 Okt. 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);
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Get Started with MATLAB finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!