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

4 views (last 30 days)
I am interested only to screen rows that starts with number or skip those rows that starts with : and # Any idea ?

Accepted Answer

Walter Roberson
Walter Roberson on 12 Oct 2016
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 Comments
Walter Roberson
Walter Roberson on 13 Oct 2016
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};

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!