Read only numerical lines from mixed text file

Hello,
I have a text file with xyz-coordinates that looks like this:
Now, I only want to import the numerical lines into a matrix with 3 columns, or import everything and select the numbers later. I tried several combinations of importdata, load, textscan, headerlines, format definitions... but it never fully works: a large portion of the data is missing, the format is not right, there's no data loaded at all... I found solutions for text files that have only text in the beginning of the file or have a fixed string at the beginning of each line, but I don't manage to convert them to a code that is suitable for my problem.
Can anyone help me?

1 comentario

KSSV
KSSV el 15 de Nov. de 2016
Attach that data as a text file or copy it here....instead of a image.

Iniciar sesión para comentar.

 Respuesta aceptada

Walter Roberson
Walter Roberson el 15 de Nov. de 2016

1 voto

You can use textscan() with format '%f%f%f' and 'CommentStyle', '#'

4 comentarios

This works perfectly.
data = textscan(fid,'%f%f%f','CommentStyle', '#');
Thanks!
Jackson Barlow
Jackson Barlow el 4 de Dic. de 2018
Is this a strenuous process for my computer in I have far more data than the aforementioned? I am simply wondering how long it would take.
Walter Roberson
Walter Roberson el 5 de Dic. de 2018
It can add up on large enough files. textscan() is one of the more efficient reading routines. You might be able to do marginally better with fscanf() if the format is very regular, but you would have to handle the various # lines yourself.
Walter Roberson
Walter Roberson el 5 de Dic. de 2018
Sometimes it can be worthwhile to invoke perl() to reformat input into something that MATLAB can handle easily. For example, for the file posted in the Question above, if the leading # are replaced with leading % then the result is something that MATLAB can load() as text.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Large Files and Big Data en Centro de ayuda y File Exchange.

Preguntada:

el 15 de Nov. de 2016

Comentada:

el 5 de Dic. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by