How to get a specific time frame from datetime?
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Kofial
le 18 Déc 2019
Commenté : Walter Roberson
le 18 Déc 2019
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 commentaires
Réponse acceptée
Walter Roberson
le 18 Déc 2019
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 commentaires
Walter Roberson
le 18 Déc 2019
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);
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Dates and Time dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!