필터 지우기
필터 지우기

Divide daytimes in before noon and after noon

조회 수: 4 (최근 30일)
Philipp Henschel
Philipp Henschel 2018년 1월 8일
댓글: Philipp Henschel 2018년 1월 15일
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!

답변 (1개)

Matt Sprague
Matt Sprague 2018년 1월 11일
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
Philipp Henschel
Philipp Henschel 2018년 1월 15일
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

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by