function [ClusterCoeff, LocalCoeffs] = ClusterCoefficient(Adj_Mat)

LocalCoeffs = nan*ones(1,size(Adj_Mat,1));

for id_row = 1:size(Adj_Mat,1)
    Adj_Mat(id_row,id_row) = 0;
end

for id_row = 1:size(Adj_Mat,1)

    % First find the in-neighbours
    InNeigh = find(Adj_Mat(id_row,:));
    
    if not(isempty(InNeigh))
        % Now, find the number of edges between these neighbours
        SubMatrix = Adj_Mat(InNeigh,InNeigh);

        if length(InNeigh)>1
            % Count the number of edges and divide by the maximum total
            LocalCoeff = sum(sum(abs(SubMatrix)>0))/(sum(sum( ones(size(SubMatrix)) - eye(size(SubMatrix)) )));
        else
            LocalCoeff = 1;
        end
        LocalCoeffs(id_row) = LocalCoeff;
    end
    
end

ClusterCoeff = mean(LocalCoeffs, 'omitnan');



end

