How to convert date and time present in same cell to a matrix having all values in elongated form like Y, M, D, H, Mi, S?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Saad Ahmed
el 1 de Oct. de 2018
Respondida: Peter Perkins
el 1 de Oct. de 2018
I have an excel file of time and want to convert the time values to datevec format. The format of time in excel file is like '1/17/2018 16:20:37', '1/17/2018 16:25:37' and so on. I want these values in this format: year, month, date, hour, minutes and seconds. Also, when I read the xlsx file in MATLAB, it automatically converts time to 12 h format like 4:20:37 pm. Please help.
0 comentarios
Respuesta aceptada
JohnGalt
el 1 de Oct. de 2018
datevec(datestr('1/17/2018 16:20:37','dd/mm/yyyy HH:MM:SS'))
and more generally
dts = {'1/17/2018 16:20:37', '1/17/2018 16:25:37'}
datevec(datestr(dts,'dd/mm/yyyy HH:MM:SS'))
Más respuestas (1)
Peter Perkins
el 1 de Oct. de 2018
I'm gonna suggest that you likely don't need to do this. Unless you are using a pretty old version of MATLAB, use datetime instead of datenum/datevec/datestr.
If you want, for example, the hour field, it's simple to get it from a datetime when you need it:
>> t = datetime({'1/17/2018 16:20:37', '1/17/2018 16:25:37'})
t =
1×2 datetime array
17-Jan-2018 16:20:37 17-Jan-2018 16:25:37
>> t.Hour
ans =
16 16
Also, you should probably be using readtable to get the timestamps and whatever else is in the spreadsheet into MATLAB. It will make life much easier.
0 comentarios
Ver también
Categorías
Más información sobre Dates and Time en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!