%% Degree Centrality of Random Graph
% Create and plot a weighted graph using a random sparse adjacency matrix. Since there are a lot of edges, use a very small value for EdgeAlpha to make the edges mostly transparent.

A = sprand(1000,1000,0.15);
A = A + A';
G = graph(A,'omitselfloops');
p = plot(G,'Layout','force','EdgeAlpha',0.005,'NodeColor','r');

%
% Calculate the degree centrality of each node. Specify the importance of each edge using the edge weights.

deg_ranks = centrality(G,'degree','Importance',G.Edges.Weight);

%
% Use discretize to place the nodes into 7 equally-spaced bins based on their centrality scores.

edges = linspace(min(deg_ranks),max(deg_ranks),7);
bins = discretize(deg_ranks,edges);

%
% Make the size of each node in the plot proportional to its centrality score. The marker size of each node is equal to the bin number (1-7).

p.MarkerSize = bins;

% Copyright 2012 The MathWorks, Inc.