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!