function [ k ] = avk( A )
%AVK  Calculates the average node degree k of a graph
%   AVK(A), returns the average node degree, A being the adjacency matrix of the network.
%
%     If A is not symmetric, i.e. comes from a digraph, the average node degree is
%     understood as the sum of in- and outdegree!
%
%  Last change:  10/2/2005 - Florian Knorn

if nargin ~= 1
    error('Please input adjacency matrix !');
else
    if size(A,1) ~= size(A,2)
        error('Please input SQUARE matrix !');
    end
end

if A ~= A' % A is not symmetric => directed graph
	k = 2*length(find(A))/size(A,1);
else % A is symmetric => undirected graph
	k = length(find(A))/size(A,1);
end