How to subcategorize dates from a datetime table?

1 visualización (últimos 30 días)
Ashfaq Ahmed
Ashfaq Ahmed el 4 de Abr. de 2023
Comentada: Peter Perkins el 5 de Abr. de 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!

Respuesta aceptada

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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by