Azzera filtri
Azzera filtri

Cell array filtering date and time using datenum

9 visualizzazioni (ultimi 30 giorni)
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.

Risposta accettata

per isakson
per isakson il 8 Ott 2017
Modificato: per isakson il 8 Ott 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

Più risposte (1)

Peter Perkins
Peter Perkins il 13 Ott 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

Categorie

Scopri di più su Dates and Time in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by