How to skip certain return points using the "find" command

7 vues (au cours des 30 derniers jours)
Benjamin
Benjamin le 24 Août 2011
I have a random wave form that has an amplitude of 5. I wish to find every point that is over the threshold of 2 and under -2, but only every 5 points. e.g. I found one point over 2, now I cannot detect another point over 2 for another 5 points. I am brand new to matlab and this is just for practice, but any help would be appreciated.

Réponse acceptée

Oleg Komarov
Oleg Komarov le 24 Août 2011
% example data
y = sin(0.1:0.1:100)*5;
% Select data over threshold
sel = y(abs(y) > 2);
% Skip every 5 (interval should be 6 because the sixth value is selected)
sel(1:6:end)

Plus de réponses (1)

Antti
Antti le 25 Août 2011
If you want also to get indexes (for some reason) with find command:
% example data
y = sin(0.1:0.1:100)*5;
% All indexes over threshold
inds = find(abs(y) > 2);
% Selected point indexes (I didn't get the point of number 6 here)
inds = inds(1:5:end);
sel = y(inds);
plot(sel,'*')
  1 commentaire
Oleg Komarov
Oleg Komarov le 25 Août 2011
The OP says: "now I cannot detect another point over 2 for another 5 points" meaning that the fifth point should be excluded.
1:5:end includes every fifth, but you have to skip that as well.
Btw, I would not call find, it is unnecessary and slows down the routine.

Connectez-vous pour commenter.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by