function r=correlation(x,y)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% function correlation
% usage: r=correlation(x,y)
%
% x and y can contain NaN
% they can have 1, 2 or 3D
% but they must be the same size
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
mask=isnan(x) | isnan(y);
indy=find(~mask);%finds ones
x=x(indy);
y=y(indy);
mX=mean(x);
mY=mean(y);
xp=x-mX;
yp=y-mY;
r=sum(xp.*yp)/sqrt(sum(xp.^2)*sum(yp.^2));