help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Help-octave Digest, Vol 30, Issue 49


From: Francesco Potorti`
Subject: Re: Help-octave Digest, Vol 30, Issue 49
Date: Sat, 20 Sep 2008 12:04:48 +0200

>Hi all I have a matrix like this: 
>A=[3 3 3 2 2 2 5 5 5 3 3 3 2 2 2 5 5 5 3 3 3 2 2 2 5 5 ]';
>B=[2 3 3 2 8 2 5 5 3 3 3 3 2 2 8 5 5 5 3 5 3 2 2 2 5 5 ]';
> 
>I want to calculate the moving  correlation coefcient of these two
>matrix (using 5 rows sample) so in the previous matrix I will calculate
>20 values, the first value uses 1 to 5, the second coeficient
>correlation will use the 2 row to 6.

The following solution is very easy but very inefficient.  It is not
good for longer vectors.  If you have very long vectors, you should
resort to vectorised code, rather than a loop.

w = 5-1;
for r = 1:length(A)-w
  C(r) = cor(A(r:r+w),B(r:r+w));
endfor

-- 
Francesco Potortì (ricercatore)        Voice: +39 050 315 3058 (op.2111)
ISTI - Area della ricerca CNR          Fax:   +39 050 315 2040
via G. Moruzzi 1, I-56124 Pisa         Email: address@hidden
(entrance 20, 1st floor, room C71)     Web:   http://fly.isti.cnr.it/


reply via email to

[Prev in Thread] Current Thread [Next in Thread]