Using textscan with lines of different length
7 次查看(过去 30 天)
显示 更早的评论
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 个评论
Guillaume
2019-3-12
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.
采纳的回答
Krishna Zanwar
2019-3-22
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.
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Import and Export 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!