Effacer les filtres
Effacer les filtres

Divide daytimes in before noon and after noon

4 vues (au cours des 30 derniers jours)
Philipp Henschel
Philipp Henschel le 8 Jan 2018
I'm working on a table with several variables. One of them is time of measurement in a 'yy-mm-dd hh:mm:ss' format. The measurements go over several days and I want to divide them into to groups: before noon and after noon. Right now I'm converting the dates to a string and then stringcompare them. Is there a better way? Since I think this way is unpleasent.
Thank you I advance!

Réponses (1)

Matt Sprague
Matt Sprague le 11 Jan 2018
You could use the Hour property of the datetime class and logical indexing to extract which times are before or noon.
t1 = datetime(18,01,1,0,0,0,'Format','yy-MM-dd hh:mm:ss');
t2 = datetime(18,01,1,23,59,59,'Format','yy-MM-dd hh:mm:ss');
t = t1:hours:t2;
%
morning = t(t.Hour<12);
afternoon = t(t.Hour>=12);
  1 commentaire
Philipp Henschel
Philipp Henschel le 15 Jan 2018
Thanks for your Answer! By now I found an different solution using the timerange feature and converting the table to a timetable
%before noon = bn, after noon = an ;
t_bn = timerange ('2013-02-15 11:00:00', '2013-02-15 16:59:59');
t_an = timerange ('2013-02-15 17:00:00', '2013-02-15 23:59:59');
fr_eb_bn = fr_eb_daytimes(t_bn,:);
fr_eb_an = fr_eb_daytimes(t_an,:);
But I'm still not happy with the solution because now separation is only for one day possible an I'm aiming to divide more days into before noon and after noon. Any further ideas?
P.S.: timeranging for every single day is not helpful

Connectez-vous pour commenter.

Catégories

En savoir plus sur MATLAB 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!

Translated by