Get duration of timerange
29 ビュー (過去 30 日間)
古いコメントを表示
Poison Idea fan
2023 年 3 月 13 日
コメント済み: Poison Idea fan
2023 年 3 月 14 日
I have a timetable. I also have a timerange corresponding to data in that timetable. I am having a hard time thinking of how to get the length, or duration, of that timerange.
I feel it should be simple but I cannot think of a compact way to do it.
0 件のコメント
採用された回答
Walter Roberson
2023 年 3 月 14 日
R1 = timerange('2018-01-01','2018-05-01','quarters')
R1S = struct(R1);
R1S.first
R1S.last
R1S.unitOfTime
R1S.last - R1S.first
R2 = timerange(seconds(2),seconds(4),'closed')
R2S = struct(R2);
R2S.first
R2S.last
R2S.unitOfTime
R2S.last - R2S.first
But what does the "length" or "duration" mean of a time range? In the case of a time range constructed from seconds it is fairly clear, but if the time range was constructed from quarter then do you need the "length" to be the number of quarters? If it was constructed from months do you need the length to be the number of months?
You can see in the quarters example that the difference between last and first is a duration, which by default gets expressed by hours minutes seconds. But because the range was constructed in quarters (a calendar duration) then looking at the duration in hours in misleading -- if you were to add that number of hours to a quarter at a different point in the year the end would probably not be the end of a quarter (quarters are not exactly equal length, and cannot be because 365 is not exactly divisible by 4)
You might have noticed the Warning message in the struct() call. timerange() does not expose any public methods or properties that allow you to get at the endpoint information, so you have to hack it.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Data Type Conversion についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!