Sorting values from a time series into two new vectors depending on the day
조회 수: 4 (최근 30일)
이전 댓글 표시
First off, I'm not very skilled at Matlab but I have som experience.
So I basically want to sort hourly water consumption data values from a ts object into two new vectors, one with values from weekdays (mon-fri) and one with values from the weekend (sat&sun). The following code works but I've a hard time getting the results on the right format.
[daynumber]=weekday(datestr(ts.Time)) %weekdays have numbers 2,3,4,5,6 sat =7 & sun=1
weekdays=zeros(6264,1); %preallocation 6246 weekday and 2496 weekend hours in a year
weekenddays=zeros(2496,1);
for i=1:8760 %8760 hours in a year
if daynumber(i)>1 && daynumber(i)<7
weekdays(i,1)=ts.data(i,1);
else
weekenddays(i,1)=ts.data(i,1);
end
end
This gives me two vectors
- Weekdays 8760x1 double
- Weekenddays 8688x1 double
What I want is two vectors with continuous values (no zeros except when the consumption is zero). With the code above i get a bunch of zeroes in between the weekend values (zeroes, 48 weekend values in a row then 120 zeros then 48 weekend values and so on). Same goes for the weekday values but the other way around.
At first I thought I'd just remove the zeros in between but then I realised that in some cases the value from ts.data is zero.
Any ideas on how I can work my way around this problem?
댓글 수: 0
채택된 답변
Torsten
2016년 1월 6일
Maybe
weekdays = ts.data(daynumber>1 & daynumber<7);
weekenddays = ts.data(daynumber=1 | daynumber=7);
?
Best wishes
Torsten.
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!