Subset of time series of fixed length?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (2)
dpb
le 12 Juin 2014
Modifié(e) : dpb
le 12 Juin 2014
...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...
2 commentaires
José-Luis
le 13 Juin 2014
Modifié(e) : José-Luis
le 13 Juin 2014
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 commentaires
Voir également
Catégories
En savoir plus sur File Operations dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!