I tried searching a function for matlab that gives the average neighbor degree of a graph.
There is a function for the same in python in network-X package. So i was wondering if there's a similar function in matlab.
***********Edit****************
I cannot convert it to an adjacency matrix.. this will occupy too much of space actually.
What i have is the following edge list(Actually this is just a test matrix.. the actual one is pretty large ) as in there's an edge between node 2 to node 1 and so on.. and yes this is an un-directed graph
2 1
3 1
4 1
5 1
1 2
3 2
4 2
1 3
2 3
5 3
1 4
2 4
5 4
1 5
3 5
4 5
Now, what i need is a function that will compute the average neighbor degree(mean neighbor degree) for this graph.
Even for large edge list, you can use Matlab to create an adjacency matrix that fits into memory using sparse
matrix:
el = [2 1; 3 1; ... ]; %// edge list, I put only a tiny sample here...
n = max( el(:) ); %// number of nodes in the graph
A = sparse( el(:,1), el(:,2), 1, n, n ); % //sparse adjacency matrix
The neighbor degree of each node is the number of neighbors
nd = sum( A, 2 ); %// degree of each node
To compute the average neighbor degree, one can construct another sparse matrix with the neighbor degree stored in each entry
ndM = sparse( el(:,1), el(:,2), nd( el(:,2) ), n, n );
The average neighbor degree can now be computed from the new matrix
av = full( sum( ndM, 2 ) ./ nd );
来源:https://stackoverflow.com/questions/25707419/matlab-function-to-compute-average-neighbor-degree