# Documentation of corr

Global Index (all files) (short | long) | Local Index (files in subdir) (short | long)

## Function Synopsis

`r=corr(vect1, vect2, lag);`

## Help text

```
r=corr(vect1, vect2, lag);

r is the correlation between the two input vectors

lag is the number of points that vect1 should lag
vect2.  For instance:

corr(a(1:10), b(1:10), 1) will produce the same as:
corr(a(2:10), b(1:9))

If lag < 0, then vect2 will lag vect1 by abs(lag)
number of points.

```

## Cross-Reference Information

This function is called by

## Listing of function corr

```function r=corr(vect1, vect2, lag);

if nargin < 3;
lag = 0;
end;

[m,n]=size(vect1);
if n == 1;
vect1 = vect1';
end
[l,k]=size(vect2);
if l == 1
vect2 = vect2';
end
if lag < 0;
tem = vect1';
vect1 = vect2';
vect2 = tem;
clear tem;
lag = abs(lag);
end
%
if nargin == 2;
v1 = (vect1 - mean(vect1));
v2 = (vect2 - mean(vect2));
elseif nargin == 3;
v1 = (vect1((lag+1):length(vect1)) - mean(vect1((lag+1):length(vect1))));
v2 = (vect2(1:(length(vect2)-lag)) - mean(vect2(1:(length(vect2)-lag))));
end
%
r = (v1 * v2) / (sqrt(v1 * v1') * sqrt(v2' * v2));

```