Clear Filters
Clear Filters

Using textscan with lines of different length

9 views (last 30 days)
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 Comment
Guillaume
Guillaume on 12 Mar 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.

Sign in to comment.

Accepted Answer

Krishna Zanwar
Krishna Zanwar on 22 Mar 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.

More Answers (0)

Categories

Find more on Data Import and Export in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!