How to subcategorize dates from a datetime table?

조회 수: 1 (최근 30일)
Ashfaq Ahmed
Ashfaq Ahmed 2023년 4월 4일
댓글: Peter Perkins 2023년 4월 5일
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