MATLAB: Indexing different time ranges from a Timetable.

indexingMATLABtimetable

So i am playing around with timetable data. The Data im working with has Both Date and TIme (in 12hr format)
I want to be able to index a couple differnt time frames.
First is I want to select all times from 11am to 12pm irrespective of the date. (when I set a time range with no date matlab just adds todays date.)
Second is I want to select all times from 11am to 12pm through a range of months say Jan-Mar

Best Answer

"First is I want to select all times from 11am to 12pm irrespective of the date. "
% Make fake data
MeasurementTime = (datetime('2018-12-01 01:00') : 0.05 : datetime('2019-04-01 11:30 PM'))';
Temperature = randi(100, size(MeasurementTime));
TT = timetable(MeasurementTime,Temperature);
% Extract hour of day (24 hr format)

hourOfDay = hour(TT.MeasurementTime);
% Determine which time stamps are between 11am and 12pm
b = [11, 12]; %[start, end] of desired time bounds (24 hr format)

selectedTimes = hourOfDay >= b(1) & hourOfDay <= b(2);
% isolate all rows of timetable between desired time bounds
TT(selectedTimes,:)
"Second is I want to select all times from 11am to 12pm through a range of months say Jan-Mar"
% Extract hour of day (24 hr format)
hourOfDay = hour(TT.MeasurementTime);
% Extract month number
monthNum = month(TT.MeasurementTime);
% Determine which time stamps are between 11am and 12pm for january to march
b = [11, 12]; %[start, end] of desired time bounds (24 hr format)
m = [1, 3]; %[start, end] of desired month bounds
selectedTimes = hourOfDay >= b(1) & hourOfDay <= b(2);
selectedMonths = monthNum >= m(1) & monthNum <= m(2);
% isolate all rows of timetable between desired time and month bounds
TT(selectedTimes & selectedMonths,:)