I want to read a badly formatted file

2 ビュー (過去 30 日間)
OldCar
OldCar 2016 年 4 月 12 日
コメント済み: OldCar 2016 年 4 月 12 日
I have a file various formatted (3 text lines, a table, 1 text line, a table) and I would like to read it. I succeded in reading the first three lines using fid=fopen('help.txt','r'); intestazione=textscan(fid, '%s',3 ,'Delimiter','\n'); but then I tried to use tblread but I din't succed. How can I do?
  2 件のコメント
Stephen23
Stephen23 2016 年 4 月 12 日
If you want us to rely on our mind-reading skills then it will be hard for us to help you. However if you upload the table then we can help you much more easily: click the paperclip button above the text box, then click both Choose file and Attach file buttons.
OldCar
OldCar 2016 年 4 月 12 日
Sorry, I have choosen the file but not attached, now is available

サインインしてコメントする。

回答 (1 件)

Walter Roberson
Walter Roberson 2016 年 4 月 12 日
tableread() can only process an entire file. You need to continue on with the textscan(), either telling it a fixed number of lines to process or giving a format that will fail when it encounters the end of the table, triggering it to stop reading. If the format of the first line after the table is compatible with the format of the first field of the table then you are going to need to read line by line and examine the contents of the line to figure out when to stop.
  1 件のコメント
OldCar
OldCar 2016 年 4 月 12 日
and how can I tell him to read 4 lines as table? and the read a single line and then a table?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeText Files についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by