function y = stdnan(x)
%STDNAN  Standard deviations for elements excluding those given by `NaN'.
%        stdnan(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 CORNAN, ADDNAN, AVGNAN, MINNAN, MAXNAN, SUMNAN.

%        Ellen R. McGrattan, 5-13-98
%        Revised, 5-13-98, 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    = std(x(k,[i,j]));
      y(i,j) = tem(1,2);
    else
      y(i,j) = NaN;
    end;
    y(j,i) = y(i,j);
  end;
end;

