function [R] = ClarkEvans3d(M);

% CL_AND_EV(M,mnnd) --- This function calculates the Clark and Evans index of 
% aggregation.  This is found by the mean nearest-neighbor distance divided by the   
% expected NND. Inputs required are the array M, in the standard format, and the   
% mean NND,found by the MNND function.

% Based on cl_and_ev by Ian McFarland, University of Washington
% Modified to handle 3-D case by Jim Work, University of South Carolina, August 13, 2003


N = size(M,1);
mnnd = meanNnd3d(M);

% Density of points.
rho = N / (9*4*100*pi);

% Expected nnd, denoted classically as r_E
r_E = .55397 / ((rho)^(1/3));

% Finds the index, R, which is the output of the function.
R = mnnd / r_E;
