Removing weekends and holidays from a TimeTable

 Réponse acceptée

Weekends is simple:
TT = TT(~isweekend(TT.Time),:) % assumes the default name, Time, for the row times
Holidays are another story, but if you have a list of the ones you care about, use ismember on TT.Time. You may need to use dateshift to "round" to whole days, depending on what your data look like. Perhaps something like
ismember(dateshift(TT.Time,'start','day'),listOfHolidays)
Also, if you have access to the Financial Toolbox, you can use that to generate a list of dates to remove.

4 commentaires

Andy
Andy le 30 Mai 2018
Is it possible to extract say only entries between 8.00am and 10.00am (inclusive) from a 4 months timetable with 10 minute data entries in it?
Sure: use the timeofday function to extract the time portion of the timestamps, then use <= (twice) to create a logical subscript.
>> d = datetime(2018,5,31,7,0:30:240,0)
d =
1×9 datetime array
Columns 1 through 4
31-May-2018 07:00:00 31-May-2018 07:30:00 31-May-2018 08:00:00 31-May-2018 08:30:00
Columns 5 through 8
31-May-2018 09:00:00 31-May-2018 09:30:00 31-May-2018 10:00:00 31-May-2018 10:30:00
Column 9
31-May-2018 11:00:00
>> t = timeofday(d)
t =
1×9 duration array
Columns 1 through 8
07:00:00 07:30:00 08:00:00 08:30:00 09:00:00 09:30:00 10:00:00 10:30:00
Column 9
11:00:00
>> i = (hours(8) <= t) & (t <= hours(10))
i =
1×9 logical array
0 0 1 1 1 1 1 0 0
Then use that to select rows of the timetable.
@Peter Perkins hi, how can i get the reverse of what you just did with weekends, How can I get rid of weekdays and keep the wekend only?
Leave out the ~.

Connectez-vous pour commenter.

Plus de réponses (1)

Sonima
Sonima le 20 Avr 2019
Modifié(e) : Sonima le 20 Avr 2019
Hi!
This works and remove the weekends from a TimeTable, but still gaps showed up on the plot!
TT = TT(~isweekend(TT.Time),:);

1 commentaire

Yes, this is to be expected. plot() positions elements by relative numeric position, and the relative numeric position of Monday to Monday is 7 days not 5 days.
You could look in the File Exchange for the various "break plot" routines. Or... you could use a time axes that was some kind of relative business days apart measure and adjust the tick labels to the associated dates.
Either way, getting zoom and pan and data tips (datacursor) right is a nuisance

Connectez-vous pour commenter.

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by