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 Center および File ExchangeLogical についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by