Hello Andy,
It seems you are looking for some assistance on how to effectively use the ‘timerange’ function to fetch data.
The ‘timerange’ function is designed to filter data by allowing us to specify a start time and an end time. According to the documentation, if the values in the timetable are datetime values, then both the start and end times should be datetime values as well. Conversely, if the values are of duration type (i.e. Time), then the start and end times must be duration values.
For applying the ‘timerange’ function to filter rows for duration values specifically between 14 hours and 22 hours, here is a helpful workaround. Split the datetime column into two separate columns, with the first column dedicated to time and the second to date. With this setup, the ‘timerange’ function can be effectively used to extract rows with duration values falling between 14 hours and 22 hours. The following code snippet illustrates how this can be achieved:
range14to22 = timerange(hours(14), hours(22), 'closed');
timeTableTT14to22 = timeTableTT(range14to22, :);
Similarly, if the first column consists of datetime values, the syntax below can be employed to fetch rows that contain data from the first half of a specific year.
halfYrRange = timerange('2020-01-01','2020-06-30','closed');
timeTableTT2020FirstHalf = timeTableTT(halfYrRange, :);
Based on my understanding, the ‘timerange’ function does not directly provide the option to apply additional filters. As a result, to exclude rows representing bank holidays and Sundays, it will be necessary to identify the indexes of these specific rows first and then filter them from the table.
Here is the output from a sample dataset that I created. The entries in my time column are spaced 30 minutes apart, and I have filtered the data to include only the entries between 2 hours to 3 hours.
For a more comprehensive understanding of the ‘timerange’ function, please consult the following documentation: https://www.mathworks.com/help/matlab/ref/timerange.html .
Hope it help!