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
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 CenterFile Exchange에서 Data Import and Export에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by