Is there a way in which I can split my data with one column having datetime (day and hour) into working and non working hours?

 채택된 답변

Jan Orwat
Jan Orwat 2016년 10월 3일

1 개 추천

Yes, you can. For example:
% assuming your data in variable called datecolumn
daytime = timeofday(datecolumn);
openinghour = duration(09, 00, 00);
closinghour = duration(18, 00, 00);
isworkinghour = (openinghour <= daytime) & (daytime <= closinghour);
workinghours = datecolumn(isworkinghour);
nonworkinghours = datecolumn(~isworkinghour);

댓글 수: 8

Tushar Agarwal
Tushar Agarwal 2016년 10월 4일
편집: Tushar Agarwal 2016년 10월 4일
Seems like "timeofday" is not a function, or not enough arguments for for cells/ double or table. I imported my data in all three forms, and still didnt work. :(
Tushar Agarwal
Tushar Agarwal 2016년 10월 4일
I tried to read as a table again, and it did work but I got stuck here. I am uplaoding a picture below.
Any help will be amazing.
Tushar Agarwal
Tushar Agarwal 2016년 10월 4일
Tried further, (sorry for the spam), but comparison between duration and Table, Datetimearray, and cell is also not possible. I am a beginner - trying everything
Jan Orwat
Jan Orwat 2016년 10월 4일
편집: Jan Orwat 2016년 10월 4일
try
daytime = Data{:,1}
using {} instead of () brackets. If result is a datetime array, then try
daytime = timeofday(Data{:,1});
it should be duration array. Then comparisons should work. isworkinghour should be logical array. Note, timeofday was introduced in 2014b.
Then you can access your data table like this:
workinghours = Data(isworkinghour, :);
nonworkinghours = Data(~isworkinghour, :);
Tushar Agarwal
Tushar Agarwal 2016년 10월 4일
Ok, thank you so much. I shall try it.
Tushar Agarwal
Tushar Agarwal 2016년 10월 5일
편집: Tushar Agarwal 2016년 10월 5일
Hello Jan,
that did work. My only problem with this (and I kinda knew this would happen), is that, though the hours seperated, the weekends are not. I need to remove all hours for the weekends, and set them as non-working hours too. Any ideas? Thank you so much
Steven Lord
Steven Lord 2016년 10월 5일
Use the day function with the 'dayofweek' option.
Tushar Agarwal
Tushar Agarwal 2016년 10월 6일
Thanks guys.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Simulink에 대해 자세히 알아보기

태그

질문:

2016년 10월 3일

댓글:

2016년 10월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by