%Number of nodes
d=10;

%Generate a symmetric matrix
M=randi([0,10],d,d);
M=(M+M');

%Graph definition

G=graph(M);
%plot(G);

%Random Sparse Matrix Generation - https://uk.mathworks.com/help/matlab/math/constructing-sparse-matrices.html

M=randi(d,d);
vd=randi([1,d]);
v=randi([-d,d],vd,1);
T=spdiags(M,v,d,d);
M=full(T)+(full(T))';

G=graph(M);
%figure
plot(G);

%Path Length - https://uk.mathworks.com/help/matlab/ref/graph.shortestpath.html?searchHighlight=shortestpath

[path,length]=shortestpath(G,7,8); %shortest path to go from node 7 to 8

%Diameter

Ms=sparse(M);
view(biograph(Ms,[],'ShowWeights','on'));
distances = graphallshortestpaths(Ms); %https://uk.mathworks.com/help/bioinfo/ref/graphallshortestpaths.html

[diameter, long_ind] = max(distances(:));
[dx,dy] = ind2sub(size(distances), long_ind);

%Number of Connected Components

cc=conncomp(G)';
vector_cc=zeros(size(cc,1),2);
i=1;
while i<=size(cc,1)
    vector_cc(i,1)=i;
    i=i+1;
end

vector_cc(:,2)=cc;

n_isol_graph=max(vector_cc(:,2)); %Number of isolated graphs

%Largest Connected Component

comp=zeros(n_isol_graph,2);

i=1;
while i<=n_isol_graph
    comp(i,1)=i;
    comp(i,2)=sum(vector_cc(:,2)==i);
    i=i+1;
end

[s_comp,n_comp]=max(comp(:,2));

%Degree Distribution - probability of having a node of degree k

deg=degree(G);
vector_deg=zeros(size(deg,1),2);
i=1;
while i<=size(deg,1)
    vector_deg(i,1)=i;
    i=i+1;
end

vector_deg(:,2)=deg;

pos_deg=unique(vector_deg(:,2));
i=1;
while i<=size(pos_deg,1)
    pos_deg(i,2)=sum(vector_deg(:,2)==pos_deg(i,1))/size(vector_deg,1);
    i=i+1;
end


%Clustering Coefficient

[A,avg_clcoef,node_clcoef]=clust_coeff(M);
