Effacer les filtres
Effacer les filtres

How to subcategorize dates from a datetime table?

2 vues (au cours des 30 derniers jours)
Ashfaq Ahmed
Ashfaq Ahmed le 4 Avr 2023
Commenté : Peter Perkins le 5 Avr 2023
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!

Réponse acceptée

Steven Lord
Steven Lord le 4 Avr 2023
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 commentaires
Ashfaq Ahmed
Ashfaq Ahmed le 4 Avr 2023
Nevermind! It is actually possible. I was trying S[1] instead. My bad!
Peter Perkins
Peter Perkins le 5 Avr 2023
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.

Connectez-vous pour commenter.

Plus de réponses (0)


En savoir plus sur Calendar dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by