function [maxdd,distrt,degr_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,nx);%Array of degrees in a graph.
%max=0;
summ=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));
degr_distr=zeros(1,maxdd);
for i=1:maxdd
    for j=1:sz(1)
        if dp(j)==i
            degr_distr(i)=degr_distr(i)+1;
        end
    end
end
distrt=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
