Using textscan with lines of different length

10 ビュー (過去 30 日間)
Drach
Drach 2019 年 3 月 12 日
回答済み: Krishna Zanwar 2019 年 3 月 22 日
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
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
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 件)

カテゴリ

Help Center および File ExchangeData Import and Export についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by