Borrar filtros
Borrar filtros

Ignoring comments when parsing

3 visualizaciones (últimos 30 días)
g
g el 22 de En. de 2019
Respondida: Walter Roberson el 22 de En. de 2019
I am currently parsing a file using the following scheme.
fmt = '%s%s';
opt = {'Delimiter','='};
[fid,msg]=fopen(file,'rt');
assert(fid>=3,msg);
C = textscan(fid,fmt,opt{:});
fclose(fid);
However, this is unable to ignore comments. If the file I am parsing has some commented lines, how can I skip those?
Thanks!

Respuesta aceptada

Walter Roberson
Walter Roberson el 22 de En. de 2019
textscan() has a 'CommentStyle' option. See <https://www.mathworks.com/help/matlab/ref/textscan.html#btghhyz-1_sep_shared-CommentStyle>
For example, specify a character such as '%' to ignore text following the symbol on the same line. Specify a cell array of two character vectors, such as {'/*','*/'}, to ignore any text between those sequences.

Más respuestas (0)

Categorías

Más información sobre String Parsing 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