Create subsets of data within a timetable
Mostrar comentarios más antiguos
I have a timetable (TT) and I need to create data subsets based on time duration vectors. The code below does what I need but I ended up with 6 timetables in my workspace, which is a problem for me because I then need to do a for loop to conduct several operations on each subset and I don't know how to iterate through different timetables. I would be so grateful if someone could tell me if there is a way to have these 6 subsets all in a single timetable so I can then have a loop iterating through them? Alternatively, how can I loop through my different timetables, considering they have different names (t1, t2, etc)? Thank you so much in advance for your help!
t1 = TT(timerange(hours(00), hours(04)), :);
t2 = TT(timerange(hours(04), hours(08)), :);
t3 = TT(timerange(hours(08), hours(12)), :);
t4 = TT(timerange(hours(12), hours(16)), :);
t5 = TT(timerange(hours(16), hours(20)), :);
t6 = TT(timerange(hours(20), hours(24)), :);
Respuesta aceptada
Más respuestas (1)
Peter Perkins
el 8 de Feb. de 2017
Another possibility is to keep the one timetable, but add a grouping variable to indicate which segment a given row is in. Then use either varfun or rowfun, specifying that grouping variable to work on each segment separately. Not sure what you're doing with each segment, so it's hard to give specific advice, but the first step probably looks something like
tt.Segment = discretize(tt.Time,hours(0:4:24),'categorical')
Categorías
Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!