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!