remove space line from a text file

조회 수: 11 (최근 30일)
sara
sara 2012년 2월 26일
댓글: Jan 2015년 10월 30일
I need to remove a space line from a text file. Any help is appreciated. Sara

채택된 답변

Jan
Jan 2012년 2월 26일
% Read the file as cell string line by line:
fid = fopen(FileName, 'r');
if fid < 0, error('Cannot open file: %s', FileName); end
Data = textscan(fid, '%s', 'delimiter', '\n', 'whitespace', '');
fclose(fid);
% Remove empty lines:
C = deblank(Data{1}); % [EDITED]: deblank added
C(cellfun('isempty', C)) = [];
% Write the cell string:
fid = fopen(FileName, 'w');
if fid < 0, error('Cannot open file: %s', FileName); end
fprintf(fid, '%s\n', C{:});
fclose(fid);
  댓글 수: 2
Jan
Jan 2012년 2월 26일
Please explain exactly, what "blanks" mean. I've added a DEBLANK in the code. Does it now do what you need?
Umar
Umar 2014년 2월 13일
Thanks :)

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

추가 답변 (1개)

ALPER AHMED
ALPER AHMED 2015년 10월 28일
편집: ALPER AHMED 2015년 10월 28일
hi Jan Simon,
how can i delete the second empty line in my text file. (there have 360 text files (angle1,angle2....angle360) and all have the same problem) any help is appreciated.
  댓글 수: 1
Jan
Jan 2015년 10월 30일
Please open a new thread for a new question. Posting a question in the section for answers of another question is confusing.

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

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by