function  y = sumnan(x)
%SUMNAN   Sum of elements ignoring elements equal to NaN.
%         For vectors, SUMNAN(X)  is the over non-`NaN' elements in X.
%         For matrices, SUMNAN(X) is a row vector containing the sums of
%         the non-`NaN' elements in each column.
% 
%         See also SUM, ADDNAN, AVGNAN, CORNAN, MINNAN, MAXNAN.

%         Ellen R. McGrattan, 5-2-97
%         Revised, 5-2-97, ERM

[m,n]  = size(x);
for j=1:n;
  i      = find(~isnan(x(:,j)));
  if ~isempty(i)
    y(j)   = sum(x(i,j));
  else;
    y(j)   = NaN;
  end;
end;
