How can I extract a specific time for a "datetime" table?
14 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Ashfaq Ahmed
le 15 Fév 2023
Réponse apportée : dpb
le 15 Fév 2023
Dear coders,
I have a simple question but I am confused how to code it. I have this datetime table (attached with the question: RESULT.mat) and I want to keep only those rows that contains time between 2:00-3:00 am and 12:00-13:00 pm. As shown in this picture -
The final datetime table should contain only these rows with the desired HourSeries. Any feedback from you will be highly appreciated! <3
0 commentaires
Réponse acceptée
Kevin Holly
le 15 Fév 2023
Modifié(e) : Kevin Holly
le 15 Fév 2023
load('RESULT.mat')
result
result.HourSeries = datetime(result.HourSeries,"Format","HH:mm")
index = hour(result.HourSeries)==12|hour(result.HourSeries)==2;
result(index,:)
Plus de réponses (2)
Sulaymon Eshkabilov
le 15 Fév 2023
Here is one partial answer that finds the data pointsat specific times, i.e. 02:00, 03:00, 12:00, 13:00 and overlooks other time points such as s12:08, for example:
R =load('RESULT.mat').result;
IDX1 = find(ismember(R.HourSeries, '02:00'));
IDX2 = find(ismember(R.HourSeries, '03:00'));
IDX3 = find(ismember(R.HourSeries, '12:00'));
IDX4 = find(ismember(R.HourSeries, '13:00'));
Rs = R([IDX1,IDX2, IDX3, IDX4, IDX4],:); % Selected
whos R Rs
dpb
le 15 Fév 2023
result.HourSeries=duration(result.HourSeries,'InputFormat','hh:mm');
ix=isbetween(result.HourSeries,hours(2),hours(4))|isbetween(result.HourSeries,hours(12),hours(13));
result=result(ix,:);
Keeps only the selected entries; you lose the rest and would have to reload the .mat file if need any other data. Doing the conversion and reSAVEing first would probably be the smart thing; then save that step going forward.
0 commentaires
Voir également
Catégories
En savoir plus sur Logical 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!