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

%	Copyright (c) 01-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) = min(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
		if ~isempty(k),			% in case not ALL elements are dummies
  			y(l) = min(x(k,l));
		else
			y(l) = dummy;
		end
	end
end	
