function [maxdd,distr]=Degree_distr(M)
%function d=Degree_distr(M) returns an array with degree numbers of the graph
% a(1) - number of nodes with degree 1, 
% a(2) - number of nodes with degree 2, etc

if nargin<1,
  error('There are no input data!')
end
sz=size(M);
if sz(1) ~= sz(2),
    error('Matrix should be square!')
end
nx=sz(1);% n - размерность матрицы (dimmension of the matrix)
%=========== Calculations======================
dp=zeros(1,n);%Array of degrees in a graph.
%max=0;
sum=0;%Sums of all degrees (to calculate the average
maxdd=0;%Max degree
for i=1:nx
    dp(i)=0;
    for j=1:nx
        if (i~=j) & M(i,j)<inf
            dp(i)=dp(i)+1;
        end
    end		%sums of the each column
    summ=summ+dp(i);
    if dp(i)>maxdd
        maxdd=dp(i);
    end
end
%maxd=max(transpose(d));
distr=summ/nx;
%distr=zeros(1,n); %Massive for degree function
%distr(1) - number of nodes with degree 1 etc
%for i=1:n,
    %distr(d(i))=distr(d(i))+1;%calculating the number of each degrees
    %end
