Identify and Obtain information from data files
1 回表示 (過去 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!