datenum(year,month,day,hr) that returns integer
1 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
采纳的回答
dpb
2022-5-13
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
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Dates and Time 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!