Cell array filtering date and time using datenum
1 次查看(过去 30 天)
显示 更早的评论
I have a cell array that consists of dates and time in the following format '30/12/2015 15:54:30'.
Using this code
numFormat = datenum(X{:,1},'dd/mm/yyyy HH:MM:SS');
Y(:,1)= round(numFormat);
Y(:,2)= hour(numFormat)*60 + minute(numFormat);
I get the error message: Error using datenum. Too many input arguments.
0 个评论
采纳的回答
per isakson
2017-10-8
编辑:per isakson
2017-10-8
Replace X{:} by char(X)
>> X = {'30/12/2015 15:54:30';'30/12/2015 15:54:30';'30/12/2015 15:54:30'};
>> numFormat = datenum(char(X),'dd/mm/yyyy HH:MM:SS')
numFormat =
1.0e+05 *
7.3633
7.3633
7.3633
0 个评论
更多回答(1 个)
Peter Perkins
2017-10-13
Think about using datetime and duration instead of datenum:
>> dt = datetime({'30/12/2015 15:54:30';'30/12/2015 15:54:30';'30/12/2015 15:54:30'},'InputFormat','dd/MM/yyyy HH:mm:ss')
dt =
3×1 datetime array
30-Dec-2015 15:54:30
30-Dec-2015 15:54:30
30-Dec-2015 15:54:30
>> d = dateshift(dt,'start','day')
d =
3×1 datetime array
30-Dec-2015 00:00:00
30-Dec-2015 00:00:00
30-Dec-2015 00:00:00
>> t = timeofday(dt)
t =
3×1 duration array
15:54:30
15:54:30
15:54:30
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Dates and Time 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!