How to subset data based on time range
이전 댓글 표시
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,
채택된 답변
추가 답변 (1개)
Guillaume
2020년 3월 5일
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
카테고리
도움말 센터 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!