function y = max9(x,dummy)
%MAX9	Maximum value excluding dummy values.
%
%	MAX9(X,DUMMY) works much the same way as MAX, except that
%	all elements containing DUMMY are ignored in the maximum process.
%	Only if all values in a row are equal to DUMMY, the result is an 
%	element of value DUMMY.
%
%
%	MAX9(X) (thus, DUMMY omitted) assumes DUMMY == NaN.
%
%	See also MIN9, MAX, MEAN9, MEDIAN9, STD9.

%	Copyright (c) 1995  W. Erasmi, Meeresphysik
%	rev. 02-02-1995 W.Erasmi

if (nargin < 2),
	dummy = NaN;
end

[m,n] = size(x);
if (m==1),					% if x is a row vector
	x = x';
	[m,n] = size(x);
end
y=zeros(1,n);
								
if isnan(dummy),			% procedure for dummy = NaN
	for l=1:n,
  		k = find(isnan(x(:,l))==0);
%		if k~=[],			% in case not ALL elements are dummies
		if ~isempty(k),			% in case not ALL elements are dummies
  			y(l) = max(x(k,l));
		else
			y(l) = NaN;
		end
	end
else							% procedure for other dummy values
	for l=1:n,
  		k = find(x(:,l)~=dummy);
		if k~=[],			% in case not ALL elements are dummies
  			y(l) = max(x(k,l));
		else
			y(l) = dummy;
		end
	end
end	
