フィルターのクリア

time to number conversion

6 ビュー (過去 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 Center および File ExchangeDates and Time についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by