Identify and Obtain information from data files
2 views (last 30 days)
Show older comments
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 Comments
Answers (1)
Matt Kindig
on 18 Apr 2013
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 Comments
See Also
Categories
Find more on Standard File Formats in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!