function  y = maxnan(x)
%MAXNAN   Largest component ignoring elements equal to `NaN'. 
%         For vectors, maxnan(X) is the largest non-NaN element in X. 
%         For matrices, maxnan(X) is a vector containing the maximum 
%         non-NaN element from each column. 
%         [Y,I] = maxnan(X) stores the indices of the maximum non-NaN
%         values in vector I.  
%
%         See also MAX, ADDNAN, AVGNAN, CORNAN, MINNAN, SUMNAN.
% 

%         Ellen R. McGrattan, 7-7-97
%         Revised, 7-7-97, ERM

[m,n]  = size(x);

for j=1:n;
  i      = find(~isnan(x(:,j)));
  if ~isempty(j)
    [y(j),ind(j)] = max(x(i,j));
  else;
    y(j)   = NaN;
    ind(j) = 0;
  end;
end;
