Min=min(X)*(1-1e-6); %A little smaller than Minmimum value of X
Max=max(X)*(1+1e-6); %A little bigger than Maximum value of X
Inc=(Max-Min)/(numbins); %Width of bins
Edges=[Min:Inc:Max]; %The Edges of the Bins, Just for Troubleshooting
Index=floor((X(:,1)-Min)/Inc)+1; %Figure out which bin each element of X goes into
% This replace the for-loop
[I,C] = ndgrid(Index,1:size(X,2));
Averages = accumarray([I(:),C(:)],X(:))./accumarray(Index,1);
