How to get a specific time frame from datetime?
3 次查看(过去 30 天)
显示 更早的评论
I have data on this time frame:
Time = [11-Sep-2019 08:10:45' 11-Sep-2019 09:10:45' '11-Sep-2019 18:10:47' '11-Sep-2019 20:10:48' '11-Sep-2019 23:10:49'];
I would like to have only from 11-Sep-2019 09:00:00 till 11-Sep-2019 19.00:00
How can I filter this?
0 个评论
采纳的回答
Walter Roberson
2019-12-18
Time = datetime({'11-Sep-2019 08:10:45' '11-Sep-2019 09:10:45' '11-Sep-2019 18:10:47' '11-Sep-2019 20:10:48' '11-Sep-2019 23:10:49'});
start_time = datetime('11-Sep-2019 09:00:00');
end_time = datetime('11-Sep-2019 19:00:00');
Time(isbetween(Time, start_time, end_time))
If you are working with timetable objects, see also timerange()
Notice the end time is coded here as 19:00 not as 19.00 as you had posted. If you need 19.00 as input, then you need to decide whether the input will be consistently using the period in that location, or whether either one might occur. If either one might occur then you will want to do string editing to conditionally replace period with colon; if only the period will occur then you could do string editing or you could use an 'InputFormat' option in the datetime() call. Notice that you used the colon in specifying the start hour; that suggests that you want to be able to specify either period or colon in that location.
2 个评论
Walter Roberson
2019-12-18
Time = datetime({'11-Sep-2019 08:10:45' '11-Sep-2019 09:10:45' '11-Sep-2019 18:10:47' '11-Sep-2019 20:10:48' '11-Sep-2019 23:10:49'});
Concentration = [1.4 0.1 2.4 0.1 0.4];
start_time = datetime('11-Sep-2019 09:00:00');
end_time = datetime('11-Sep-2019 19:00:00');
mask = isbetween(Time, start_time, end_time);
selected_Time = Time(mask);
selected_Concentration = Concentration(mask);
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!