extracting datetime from csv file

조회 수: 18 (최근 30일)
Rose
Rose 2019년 12월 30일
댓글: Star Strider 2019년 12월 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!

채택된 답변

Star Strider
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
  댓글 수: 2
Rose
Rose 2019년 12월 30일
Thank you! That works perfectly!
Star Strider
Star Strider 2019년 12월 30일
As always, my pleasure!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Tables에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by