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.

采纳的回答

per isakson
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

更多回答(1 个)

Peter Perkins
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

类别

Help CenterFile Exchange 中查找有关 Dates and Time 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by