Using textscan with lines of different length

4 Ansichten (letzte 30 Tage)
Drach
Drach am 12 Mär. 2019
Beantwortet: Krishna Zanwar am 22 Mär. 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 Kommentar
Guillaume
Guillaume am 12 Mär. 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.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Krishna Zanwar
Krishna Zanwar am 22 Mär. 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.

Weitere Antworten (0)

Kategorien

Mehr zu Data Import and Export finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by