MATLAB: How to extract data corresponding to a date and time

datetime

I have a time series data W (315360000×1)
The number of rows is equal to 6000 x 144 x 365 , which is 6000 measures every 10 minutes (sampling rate 10 Hz) times the number of 10 minutes in a day (144) times the number of days in a year (365). W is thus obtained for the year 2011.
I have another file T.csv, which contains just the dates and times. I have imported this file into matlab as a cell array and converted it onto a datetime file (t) as shown below:
I want to use the time in 't' and extract data 1 hour before the given time and 1 hour after the given time (i.e extract 2 hours of data)
For ex: For t(1,1) which is 2015/10/04 13:38:33, I want to get data from W corresponsing to (2015/10/04 12:28:33 to 14:28:33)
This is how far I've gotten:
t1 = datetime(2011,01,01,00,00,00);
t2 = datetime(2011,12,31,23,59,59);
dates = t1:seconds(0.1):t2;
tminus=t-minutes(60);
tplus=t+minutes(60);
Thanks,

Best Answer

Here's how to get the indices of the datetime array that are within +/- 1 hour of the target time.
% Create datetime array
t1 = datetime(2011,01,01,00,00,00);
t2 = datetime(2011,02,01,00,00,00);
dates = t1:seconds(0.1):t2;
% Determine which datetime values are within
% +/- 1 hour from time t
t = datetime(2011,01,15,12,30,00);
idx = dates > t-hours(1) & dates < t+hours(1);
idx is a logical vector the same size as dates.