Identify and Obtain information from data files

조회 수: 2 (최근 30일)
Miguel Ángel
Miguel Ángel 2013년 4월 18일
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!

답변 (1개)

Matt Kindig
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);

카테고리

Help CenterFile Exchange에서 Standard File Formats에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by