function y = cornan(x)
%CORNAN Correlations for elements excluding those given by `NaN'.
% cornan(X) is a matrix of correlation coefficients formed
% from array X whose each row is an observation, and each
% column is a variable. Any observations given by `NaN' are
% ignored.
%
% See also CORRCOEF, ADDNAN, AVGNAN, MINNAN, MAXNAN, SUMNAN.
% Ellen R. McGrattan, 2-6-97
% Revised, 2-10-97, ERM
[m,n] = size(x);
y = eye(n);
for i=2:n;
for j=1:i-1;
k = find(~isnan(x(:,i)) & ~isnan(x(:,j)));
if ~isempty(k)
tem = corrcoef(x(k,[i,j]));
y(i,j) = tem(1,2);
else
y(i,j) = NaN;
end;
y(j,i) = y(i,j);
end;
end;