Convert data table to datetime

151 次查看(过去 30 天)
I have data shown in the image.
I want to convert the second row into a datetime vector, but InputFormat doesn't work.
It's a number, e.g. 201401010000 meaning jan 1st 2014 00:00.
I tried datetime( BLA,'InputFormat','yyyyMMddHHmm')

采纳的回答

Adam Danz
Adam Danz 2021-5-5
编辑:Adam Danz 2021-5-6
> It's a number, e.g. 201401010000 meaning jan 1st 2014 00:00.
x = 201401010000;
dt = datetime(string(x),'InputFormat','yyyyMMddHHmm')
dt = datetime
01-Jan-2014
The 'format' property specifies the output format.
x can be a column of values.
  3 个评论
Adam Danz
Adam Danz 2021-5-6
> I want to convert the second row into a datetime vector
> I would like to e.g. convert it to a timetable
Those are two very different questions.
I've updated my answer. After converting the column to datetime use
Raphael Willi
Raphael Willi 2021-5-6
Aha, I got it now thanks. I did it with
TT = table2timetable(data(:,3),'RowTimes',datetime(string(data{:,2}),'InputFormat','yyyyMMddHHmm'));

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Type Conversion 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by