Sorting values from a time series into two new vectors depending on the day
1 回表示 (過去 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 件)
参考
カテゴリ
Help Center および File Exchange で Time Series Events についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!