extracting datetime from csv file
조회 수: 20 (최근 30일)
이전 댓글 표시
Hey there,
I'm trying to import a csv file with sensor data, which are measurements on set times.
The second column of the file contains the date time stamps of the sensor values, which are stored in the columns afterwards (3th, 4th, 5th column etc).
The format of the time stamps is the following: 2016-08-10 00:39:47+00:00
Now i'm facing 2 difficulties, first of all, this time stamp is not in accordance with the usual date time stamp due to the addition of +00:00, which is the same addition for every time stamp and could thus be removed (if I figure out how).
Secondly, I cant seem to get the datetime command to work for my file... I have tried the following code:
sensordata=datetime('Measurement.csv','Range', 'B2:B41') %but this does not work at all because range is not allowed
%I also tried first extracting only the second column into a cell array, and then afterwards using the datetime command, but this also resulted in the error below
January=readtable('Measurement.csv')
sensordata=January(:,2);
sensordataarray=table2array(sensordata);
time=datetime(sensordataarray,'Locale', 'en_US');
Error using datetime (line 636)
Could not recognize the format of the date/time text using the locale 'en_US'. You can specify a format using the
'InputFormat' parameter.
Any clues on how to remove the +00:00 (which i assume is part of the error as well), or how to get an array with datetime values?
Thank you!
댓글 수: 0
채택된 답변
Star Strider
2019년 12월 30일
I am not certain what the ‘+00:00’ does, however eliminating it is straightforward.
Try this:
t = datetime('2016-08-10 00:39:47+00:00', 'InputFormat','yyyy-MM-dd HH:mm:ss+00:00')
producing:
t =
datetime
10-Aug-2016 00:39:47
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Tables에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!