How to use textscan to read this .dat file? (Part 2)

1 回表示 (過去 30 日間)
Hsinho
Hsinho 2015 年 5 月 22 日
コメント済み: Hsinho 2015 年 5 月 22 日
Hi, I have another similar but more complicated formatted data. I still have a trouble to write correct arguments of "textscan" to read it.
There are 8 data in []. I want each data can be in a column, respectively.
Please find the attached file for the data. Thank you!
  3 件のコメント
Stephen23
Stephen23 2015 年 5 月 22 日
Hsinho
Hsinho 2015 年 5 月 22 日
I attached the file.

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

採用された回答

Stephen23
Stephen23 2015 年 5 月 22 日
編集済み: Stephen23 2015 年 5 月 22 日
Given the file formatting given in your last question, this will read the numeric data:
fmt = repmat('%f',1,8);
fmt = ['{%*q%f%*q[',fmt,']%*q[',fmt,']%*q[',fmt,']}'];
fid = fopen('temp.txt','rt');
A = cell2mat(textscan(fid,fmt,'Delimiter','":, ', 'MultipleDelimsAsOne',true));
fclose(fid);
Although strictly speaking the final group of numeric values should be strings, as they occur within double quotation marks. The quotation marks around numeric values makes parsing the data much more difficult and less robust.
The code was tested on this file:
  1 件のコメント
Hsinho
Hsinho 2015 年 5 月 22 日
Thank you for answering! This is exactly what I need.

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

その他の回答 (0 件)

カテゴリ

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