time to number conversion

조회 수: 2 (최근 30일)
joseph Frank
joseph Frank 2012년 7월 22일
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

채택된 답변

Geoff
Geoff 2012년 7월 22일
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');

추가 답변 (0개)

카테고리

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