Trouble converting timestamp using date and date_vectors

1 回表示 (過去 30 日間)
BenL
BenL 2017 年 2 月 13 日
コメント済み: Walter Roberson 2017 年 2 月 13 日
1) I have 6 variables, ref_year,mth,day,hr,min,sec that corresponds to a reference time. I am having trouble getting MATLAB to recognise it as a date vector when I put them into a single 1x6 matrix. How could I convert them into a datenum?
I understand DateVector function https://www.mathworks.com/help/matlab/ref/datenum.html#inputarg_DateVector accounts for it:
If an element falls outside the conventional range, datenum adjusts both that date vector element and the previous element. For example, if the minutes element is 70, datenum adjusts the hours element by 1 and sets the minutes element to 10. If the minutes element is -15, then datevec decreases the hours element by 1 and sets the minutes element to 45. Month values are an exception. datenum sets month values less than 1 to 1.

採用された回答

Walter Roberson
Walter Roberson 2017 年 2 月 13 日
base_ts = datenum([double([ref_year, ref_mth, ref_day, ref_hr, ref_min]), double(ref_sec)]);
timestamp = base_ts + secs_after_datenum / (24*60*60);
  2 件のコメント
BenL
BenL 2017 年 2 月 13 日
hi Walter, oh so the trick is to double it!
Walter Roberson
Walter Roberson 2017 年 2 月 13 日
Yes. Notice too that I used two different doubles, one for the int32 and one for the single: if I had used [] to put everything into the same vector first before doing the double() then the single would have been converted to int32 by the rules of []

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeTime Series Objects についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by