How to subcategorize dates from a datetime table?

1 次查看(过去 30 天)
Hi all,
I have a datetime table in this Period.mat file (attached) where I have a date list starting from 01/01/2005 to 12/31/2019. I want to sub-categorize the datetime table like this -
01/01/2005 to 12/31/2007
06/01/2006 to 06/31/2008
01/01/2007 to 12/31/2009
06/01/2008 to 06/31/2010
01/01/2009 to 12/31/2011
06/01/2010 to 06/31/2012
........
......
....
01/01/2017 to 12/31/2019
06/01/2018 to 06/31/2019
Eahc of these date range can be in an array. So, there will be a big cell array that contains each of these sub group. Can anyone please give me an idea on how to do that?
Any feedback will be highly appreciated!

采纳的回答

Steven Lord
Steven Lord 2023-4-4
If you have a timetable use a timerange to index into it to retrieve the appropriate section of the timetable then perform whatever calculations you need on those sections. I don't think groupsummary will do what you want here because the groups overlap.
  3 个评论
Ashfaq Ahmed
Ashfaq Ahmed 2023-4-4
Nevermind! It is actually possible. I was trying S[1] instead. My bad!
Peter Perkins
Peter Perkins 2023-4-5
Much as in your other similar question, I thiknk you want to end up with a table that has your timerange's (or maybe a text representation, or maybe both) in one variable, and a cell array containing different-length datetime vectors in another.
As Steve says, you can't use groupsummary or a grouped varfun here, because the "groups" overlap. You'll need to loop and use each timerange separately.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by