How to remove lines that starts either : and # using regexp
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 ?
0 comentarios
Respuesta aceptada
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
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};
Más respuestas (0)
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!