time to number conversion

2 visualizaciones (últimos 30 días)
joseph Frank
joseph Frank el 22 de Jul. de 2012
I have a cell array that has the following format: v0={'1/4/2011','12:17:09'} I converted the date to number using the datenum(v0(1,1),'mm/dd/yyyy'); but the question is how to convert the time '12:17:09' to a number? is it possible to merge v0(1,1) with v0(1,2) to obtain the date using timen=datenum(time,'dd/mm/yyyy HH:MM:SS')? so basically I am ok with conversing time alone to number or date & time (merged) to number. Any help is greatly appreciated

Respuesta aceptada

Geoff
Geoff el 22 de Jul. de 2012
From memory, if you use datenum to just get the time with no date, it doesn't return a number between 0 and 1. But you can get around that with mod.... So here's one option:
d = datenum(v0{1}, 'mm/dd/yyyy') + mod(datenum(v0{2}, 'HH:MM:SS'), 1);
The other way is to construct a string with both combined:
str = [v0{1}, ' ', v0{2}];
d = datenum(str, 'mm/dd/yyyy HH:MM:SS');

Más respuestas (0)

Categorías

Más información sobre Dates and Time en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by