datenum(ye​ar,month,d​ay,hr) that returns integer

I need a datenum(year,month,day,hr) that returns an integer, where year, month, day, and hr are vectors of integers.
motivation: I am trying to do this for fast lookup of many dates in a large table, where each row contains data for an hourly sample. Therefor the output of datnum will become the indices of a sparse matrix containing the row indices of the original table of data.

 採用された回答

dpb
dpb 2022 年 5 月 13 日

0 投票

Wrong approach.
Instead, convert the table to a timetable; there are direct, builtin functions to return by rowtimes either individual records or those matching a time span, etc., ...

2 件のコメント

dpb
dpb 2022 年 5 月 13 日
Addendum -- are the table entries complete? If so, then it's simply hours(tWanted-tZero) + 1 where tWanted is the desired hour and tZero is the origin of the table using the datetime class.
Otherwise, I think the other idea is still the better solution.
Chris Hooper
Chris Hooper 2022 年 5 月 14 日
awesome thanks!

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeTime Series Objects についてさらに検索

タグ

質問済み:

2022 年 5 月 13 日

コメント済み:

2022 年 5 月 14 日

Community Treasure Hunt

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

Start Hunting!

Translated by