Identify and Obtain information from data files
조회 수: 2 (최근 30일)
이전 댓글 표시
Hello:
I have to read several .csv format, and I want to get different information… I think the best way to explain my problem is through an example .CSV file:
*Station 2
*Upload Time = Ag 10 2012 20:23:49
#column 1 velocity
#column 2 temperature
1.4 20
5.7 3
[…]
Firstly, I want to get the Julian Time (datenum), but I need to obtain the date from that string line (different position in the others .csv)
Secondly, I want to read the numerical values, clearly separated from the text (identified through * and # lines).
I have tried , fopen, fgetl, fscanf…but I didn’t make it work :(
Thanks in advance!
댓글 수: 0
답변 (1개)
Matt Kindig
2013년 4월 18일
To read the numeric values, I would use textscan() with the 'CommentStyle' option, such as:
str = fileread('/your/file/name.txt');
MyData = textscan(str, '%f %f', 'CommentStyle', '*#')
To get the date, I would use regular expressions:
Time = regexp(str, '^\*Upload(\s+)Time(\s*)\=(?<Time>[^\n]+)$', 'names', 'lineAnchors');
Time = datenum(Time.Time);
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Standard File Formats에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!