If a file contains more than one consecutive empty lines, they are replaced by one empty line.
% reading file
fid=fopen(outFile,'rt');Data = textscan(fid,'%s','Delimiter','\n');Data=Data{1}; % get rid of nesting
k=1; emptylines_occured=0;for j=1:numel(Data) if ~strcmp(Data(j),'') % not empty line
if emptylines_occured newData{k}=''; k=k+1; emptylines_occured=0; end newData(k)=Data(j); k=k+1; else % empty line
emptylines_occured=1; endendfclose(fid);% writing file
fid=fopen(outFile,'wt');for j=1:numel(newData) fprintf(fid, '%s\n',newData{j});endfclose(fid);
Is there a more concise way?
Best Answer