function [x,icount]=sortave(a,b,n);
%function [x,icount]=sortave(a,b,n);
%               a is independent variable,
%			b is dependent variable,
%               n is array of values to divide a into
%               x is array of length n that represents ave of b in each bin
x=[];
icount=[];
for i=1:length(n)-1
     find((a>=n(i))&(a<n(i+1)));
	icount(i)=length(ans);
     if icount(i)>0
	     x(i)=mean(b(ans));
     end
end
find(a>n(length(n)));
icount(length(n))=length(ans);
if icount(length(n))>0
	x(length(n))=mean(b(ans));
else
     x(length(n))=0;
end
