How to remove lines that starts either : and # using regexp

조회 수: 3 (최근 30일)
Tunechi
Tunechi 2016년 10월 12일
댓글: Tunechi 2016년 10월 13일
I am interested only to screen rows that starts with number or skip those rows that starts with : and # Any idea ?

채택된 답변

Walter Roberson
Walter Roberson 2016년 10월 12일
filecontent = fileread('NameOfTheFile.txt');
newcontent = regexprep(filecontent, '^[#:].$', '', 'lineanchors', 'dotexceptnewline');
You can use textscan() on the string newcontent:
numcols = 18
fmt = repmat('%g', 1, numcols);
datacell = textscan(newcontent, fmt, 'CollectOutput', 1);
data = datacell{1};
  댓글 수: 5
Walter Roberson
Walter Roberson 2016년 10월 13일
filecontent = fileread('NameOfTheFile.txt');
newcontent = regexprep(filecontent, '^[#:].*$', '', 'lineanchors', 'dotexceptnewline');
numcols = 18;
fmt = repmat('%f', 1, numcols);
datacell = textscan(newcontent, fmt, 'CollectOutput', 1);
data = datacell{1};
Tunechi
Tunechi 2016년 10월 13일
Thank you

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by