Borrar filtros
Borrar filtros

Using textscan with lines of different length

9 visualizaciones (últimos 30 días)
Drach
Drach el 12 de Mzo. de 2019
Respondida: Krishna Zanwar el 22 de Mzo. de 2019
Hello everyone,
I'm trying to read a .txt file with textscan. Here is a part of the file:
27-03-2018 12:21:21 -> Computing phases...
27-03-2018 12:21:21 -> Computing horizontal phase for camera (0,1,1) ...
27-03-2018 12:21:21 -> Unwrapping phase level 0 ... Done
27-03-2018 12:21:21 -> Unwrapping phase level 1 ... Done
================================================
27-03-2018 13:21:55 -> Exporting (23,1,1)
================================================
The file has several thousand lines. Essentially every line has date, time, an arrow and a message. The message can contain numbers and strings and can have any number of strings and numbers. The length of the lines is not known.
The file also contains lines of several "=" as you can see. It is not known when the lines of equal singns appear.
My question is now what my formatSpec has to look like. I have no idea what I got to with changing length of lines.
Thanks alot for any help!
Edit: I found this thread:
It seems to solve my problem, I will try it.
  1 comentario
Guillaume
Guillaume el 12 de Mzo. de 2019
It's easier for us if you actually attach a demo text file.
What output are you wanting out of that?
Personally, I'd just read the whole file in one go. A simple regular expression after that would allow you to extract date, time and text while ignoring all the ==== lines, if that's what you're after. The whole thing could be done in 3 lines.

Iniciar sesión para comentar.

Respuesta aceptada

Krishna Zanwar
Krishna Zanwar el 22 de Mzo. de 2019
You can get the line as an input using the function fgetl, it will take all the values in a line regardless of the datatypes and the size of line.
tline = fgetl(fileID);
And then you can extract anything you want from 'tline' string.

Más respuestas (0)

Categorías

Más información sobre Data Import and Export 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