function b=maxpos(a,fact);
% maxpos calcultes the positions of local maxima and minima in the columns
% of a.
% b: resultant matrix : local maxima :1
%                     : local minima :-1
% fact: definition of local : minimum difference between maximum and minimum
% to be accepted as local maximum or minimum. fact times maximum value.
%
[r,c]= size(a);
b(r,c)=0;
w=max(max(a))*fact;
for j1=1:c;
	posmax=1;
	posmin=1;
	lmax=a(1,j1)-w;
	lmin=a(1,j1)+w;
	for i1=1:r
		val= a(i1,j1);
		if (val > lmax) & (val-lmin) > w
			lmax=val;
			posmax=i1;
			b(posmin,j1)=-1;
			lmin=val-w-1;		
		end
		if (val<lmin) & (lmax-val) > w
			lmin=val;
			posmin=i1;
			b(posmax,j1)=1;
			lmax=val+w+1;	
		end;
	end;
end;
