How to exclude the center/current number when performing movmax?

3 vues (au cours des 30 derniers jours)
liu James
liu James le 2 Déc 2016
Im trying to create the Donchian Channel which uses the preceding 20day high. So I figure to use movmax but it includes the current/center number.
A = [4 8 6 -1 -2 -3 -1 3 4 5];
M = movmax(A,[2 0])
M =
4 8 8 8 6 -1 -1 3 4 5
Is there a way to not include the center value?
  1 commentaire
Adam
Adam le 2 Déc 2016
Not that I can see using movmean. You can program your own version easily enough though with just a moving window and your own defined function

Connectez-vous pour commenter.

Réponse acceptée

Chris Turnes
Chris Turnes le 5 Déc 2016
There's no direct way to exclude the current point in a given window with the moving statistics functions. However, since you want a trailing maximum in this particular answer, it is fairly easy to get around. As Jan pointed out, a 20-point trailing maximum that excludes the current point can be computed as a 19-point trailing maximum with a 1-point shift. So, you should be able to just do:
movmax([-Inf x(1:(end-1))], [18 0]);
I believe this should be equivalent to what you want (although you'll have to decide what should happen for the first point, where you'd have a window only containing the current point).

Plus de réponses (2)

Andrei Bobrov
Andrei Bobrov le 2 Déc 2016
Modifié(e) : Andrei Bobrov le 2 Déc 2016
Let x - your data
One way
m = 20;
M = conv2(x(:),[zeros(m+1,1); ones(m,1)]/m,'same');
M = M(m+1:end);
Other way
m = 20;
n = numel(x);
M = mean(x(hankel(1:n-m+1,n-m+1:n)),2);
  2 commentaires
Adam
Adam le 2 Déc 2016
Isn't that a mean?
Andrei Bobrov
Andrei Bobrov le 2 Déc 2016
Hi Adam! I have corrected my answer

Connectez-vous pour commenter.


Jan
Jan le 2 Déc 2016
The max of the preceeding 20 elements without the current element is the same as the former max of the preceeding 19 elements.
So please post some input data and the wanted output data.

Catégories

En savoir plus sur Descriptive Statistics 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!

Translated by