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

5 Ansichten (letzte 30 Tage)
Tunechi
Tunechi am 12 Okt. 2016
Kommentiert: Tunechi am 13 Okt. 2016
I am interested only to screen rows that starts with number or skip those rows that starts with : and # Any idea ?

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 12 Okt. 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 Kommentare
Walter Roberson
Walter Roberson am 13 Okt. 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};

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Data Import and Export finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by