function [mcrowding] = meanCrowd2d(ARRAY);
% MEANCROWD(ARRAY) --- Determines Lloyd's Mean Crowding index for an ARRAY of 
% points.  The ARRAY should be in standard format.  

% Initialize matrix for 'no. of others' values, per individual.
OTHERS = [];

% Now, the big loop.  For each point i, the distance to each other point
% will be calculated, and stored as DISTi.  Then, the number of points 
% less than 6 BL away is found; 6 BL is the radius of our "ambit", since 
% this was how the field size was calculated. 
for i = 1:size(ARRAY,1)               % For each individual...
        
        DISTi = [];
        for j = 1:size(ARRAY,1)           % ...to each other...
            
            % ...calc. the distance.
            dist = dist2d(ARRAY(i,2),ARRAY(i,3),ARRAY(j,2),ARRAY(j,3));
            
            DISTi = [DISTi dist];           % DISTi matrix is built.
        end
        
        N = find(DISTi < 6.0);              % Determine the number of 
                                            % dist. under 6 for this point.
        
        n = size(N,2) - 1;                  % Determine no. of "others"; 1
                                            % is subtracted, since there 
                                            % will be a zero val in DISTi
                                            % for the dist. from i to 
                                            % itself.
                                            
        OTHERS = [OTHERS n];                % Build matrix of "other" vals.
        
end                             % End the big loop, go on to next point.
   
% Now, find the mean no. of others per individ., the Mean Crowding.
mcrowding = sum(OTHERS) / size(ARRAY,1);   