How to remove lines that starts either : and # using regexp
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 ?
0 Kommentare
Akzeptierte Antwort
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
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};
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Data Import and Export finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!