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

3 vues (au cours des 30 derniers jours)
Tunechi
Tunechi le 12 Oct 2016
Commenté : Tunechi le 13 Oct 2016
I am interested only to screen rows that starts with number or skip those rows that starts with : and # Any idea ?

Réponse acceptée

Walter Roberson
Walter Roberson le 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 commentaires
Walter Roberson
Walter Roberson le 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};
Tunechi
Tunechi le 13 Oct 2016
Thank you

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by