Subset of time series of fixed length?
1 次查看(过去 30 天)
显示 更早的评论
How do I search for the indices in a vector for a subset of a fixed length? Say, I have a vector of length 100. The average values of the indices between 87 to 91 (fixed length 5) is less than 0.5, which is the desired condition to find the subset. Is there any easy way to search over this hundred length vector other than using a loop and fixed window of length 5?
0 个评论
回答(2 个)
dpb
2014-6-12
编辑:dpb
2014-6-12
...the average values of the indices between 87 to 91 (fixed length 5) is less than 0.5...
I'll presume you mean the average value of the contents of the vector between the two points.
idx=5*(find(mean(reshape(v,5,[]))<0.5)-1).'+1;
will be the beginning of the group if you're content to use a non-sliding window of five.
If it's a requirement to use the sliding window,
f=filter(0.2*ones(1,5),1,v);
will give the mean vector to search over. Of course, it has four values at the beginning that are startup values that you'll want to discard.
ADDENDUM
Example for the last...
>> v=rand(20,1);
>> f=filter(0.2*ones(1,5),1,v);
>> m=[];for i=1:16,m(i)=mean(v(i:i+4));end
>> [f [zeros(4,1); m.']]
ans =
0.1298 0
0.2762 0
0.4057 0
0.4959 0
0.6053 0.6053
0.5347 0.5347
0.5373 0.5373
0.4456 0.4456
...
0.6384 0.6384
0.6106 0.6106
0.5418 0.5418
0.6149 0.6149
0.4903 0.4903
>>
I abbreviated the output manually...
José-Luis
2014-6-13
编辑:José-Luis
2014-6-13
myTest = @(x) prctile(x,5)>10 & prctile(x,95) < 200;
test_mat = hankel(1:10,1:10);
test_mat = test_mat(1:sliding_window_size, 1 : numel(x) - sliding_window_size + 1);
myTest(x(test_mat));
Further gains can be obtained if you can figure out a way of not calling prctile() twice. Maybe using quantile() instead as it accepts multiple values as input.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 File Operations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!