필터 지우기
필터 지우기

datetime - time only - 2016a

조회 수: 28 (최근 30일)
andytodd.msp
andytodd.msp 2020년 9월 7일
댓글: andytodd.msp 2020년 9월 7일
Hi all, hope you are doing well!
I've got a question which I'm sure is very simple to anyone with any significant matlab experience!
I'm using 2016a, and am trying to filter some measuement data based on the date and time - for example, I want to compile all daytime data and all night time data into seperate graphs.
My issue is with the datetime command. when using the line of code below, is basically returns '0' for all entries, as the timedate command is including todays date - whereas the measurement data has been taken previously.
I have a 264x1 double containing all measurement values, and a 264x1 datetime with sample times - so if anyone can think of a simpler way for me to do this it would be greatly appreciated!
Thanks in advance for any help!
daytimeyn=timedate < (datetime('06:59:00','InputFormat','HH:mm:ss'))
nightla90=la90(daytimeyn==0);

채택된 답변

Steven Lord
Steven Lord 2020년 9월 7일
Use the timeofday function defined for datetime arrays.
>> timeofday(datetime('now')) % It is 3:12 PM as I type this
ans =
duration
15:12:56
Fifteen hours, twelve minutes, fifty-six seconds after midnight. Compare this against a duration, like check and see if this is between 9 AM and 5 PM:
>> is9To5 = @(t) hours(9) <= timeofday(t) & timeofday(t) <= hours(17);
>> is9To5(datetime('now')) % true as I type this
  댓글 수: 2
Walter Roberson
Walter Roberson 2020년 9월 7일
Another approach is
timedate - dateshift(timedate, 'start', 'day')
andytodd.msp
andytodd.msp 2020년 9월 7일
Thank you both - thats great!
Steven, I found your method easier to implement, but thanks to you both for the help!
Andy

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

태그

제품


릴리스

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by