필터 지우기
필터 지우기

CSV file import with timestamp

조회 수: 5 (최근 30일)
Manga
Manga 2012년 3월 29일
I have csv data in the following format
value, timestamp, id
1.48,"2011-02-07 11:27:18+11",1
which I would like to import into Matlab so that I can look at the differences in successive time stamps. So I would like to convert the time of minutes to seconds and plot the difference. What is the best way to import this data?

채택된 답변

Marlies
Marlies 2012년 3월 29일
To import formatted data, textscan is usually a good option.
Textscan requires you to define a format. Assuming you want to separate all the elements in the file (value, every component from the timestamp separately, id-number), your format could look like this:
fmt = %f "%u-%u-%u %u:%u:%u+%u" %u
In this format; the '%f' and '%u' represent the datatypes that MATLAB is supposed to use for the data it reads (floating point, integer). All the other signs ("-:+) are 'literals'. They tell MATLAB that it will literally find a colon (that should be ignored).
In addition, you will need to define in the textscan-command that the delimiter is a comma
textscan(fid,fmt,'delimiter',',')
Hope this helps
Marlies

추가 답변 (1개)

Kye Taylor
Kye Taylor 2012년 3월 29일
The assignment
fmt = %f "%u-%u-%u %u:%u:%u+%u" %u
should be
fmt = '%f "%u-%u-%u %u:%u:%u+%u" %u'
(notice the single quotes). To make the unpacking of output from textscan slightly easier, you could define fmt as below. Note the fopen and fclose statements before and after invoking textscan.
fmt = '%f%q%f';
fid = fopen('yourFileName.csv');
nowInMatlab = textscan(fid,fmt,'delimiter',',');
fclose(fid);

카테고리

Help CenterFile Exchange에서 Text Data Preparation에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by