Effacer les filtres
Effacer les filtres

Cell array filtering date and time using datenum

9 vues (au cours des 30 derniers jours)
AA
AA le 8 Oct 2017
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.

Réponse acceptée

per isakson
per isakson le 8 Oct 2017
Modifié(e) : per isakson le 8 Oct 2017
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

Plus de réponses (1)

Peter Perkins
Peter Perkins le 13 Oct 2017
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

Catégories

En savoir plus sur Dates and Time dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by