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

3 visualizaciones (últimos 30 días)
Tunechi
Tunechi el 12 de Oct. de 2016
Comentada: Tunechi el 13 de Oct. de 2016
I am interested only to screen rows that starts with number or skip those rows that starts with : and # Any idea ?

Respuesta aceptada

Walter Roberson
Walter Roberson el 12 de Oct. de 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 comentarios
Walter Roberson
Walter Roberson el 13 de Oct. de 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};

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by