How to subset data based on time range
Mostra commenti meno recenti
Hi,
I am wondering how to subset data based on time range ? For example I would like to subset the maximum number of rows that fall within an 18 hours time range in the table below:
data = {"2017-01-12 09:50:46" "2017-01-15 13:50:46" "2017-01-15 14:50:50" "2017-01-15 17:52:06" "2017-01-15 18:52:22" "2017-01-16 11:52:22" "2017-01-19 09:52:22"}';
t = cell2table(data);
t.data = datetime(t.data, 'InputFormat', 'yyyy-MM-dd HH:mm:ss')
The thing is, I don’t know what is the start point or the end point. All I know is that the correct answer is the most inclusive one (i.e the one with the largest number of rows). In the example here, the correct answer is t.data(2:5) because all the points fall within 18 hours of each other and because it is the answer with the largest number of rows (4). The data is set up in a way where there can only be one correct answer (only one combination has the largest number of rows). I hope I am being clear.
How would I do that ?
Thank you,
Risposta accettata
Più risposte (1)
Guillaume
il 5 Mar 2020
It's not too clear what you mean by subsetting.If you want to bin the dates in ranges of 18 hours then use discretize:
discretize(t.data, 'hours(18)') %split into 18 hours bins. Returns the bin indices
Categorie
Scopri di più su Logical in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!