Computing average path length
显示 更早的评论
I'm using karate.gml dataset, from two visualization software gephi and SocNetV both gives me an average path length of 2.408. I want to compute the average path length in matlab using the same dataset, but mine gives me 1.76. My matlab procedure is below:
I add the distance {d} returned by the shortestpath function {[P,d] = shortestpath(G,c,nodesize);} to an array I've declared and afterwards find the mean. Not sure what I'm doing wrong.
size = nodesize;
x = [];
for c = 1:size
[P,d] = shortestpath(G,c,nodesize);
x = [x, d];
end
answer = mean(x)
1 个评论
Walter Roberson
2018-9-20
I would tend to think that average path length would include alternative paths, not just the shortest path.
采纳的回答
更多回答(1 个)
nodesize = numnodes(G);
thesize = nodesize;
x = zeros(thesize,1);
for c = 1:size
[P,d] = shortestpath(G,c,nodesize);
x(C) = d ;
end
answer = mean(x)
7 个评论
Isaac Osei Agyemang
2018-9-20
KSSV
2018-9-20
What is value of thesize?According to the above code...x should be a vector. Show us your complete code.
Isaac Osei Agyemang
2018-9-20
编辑:Walter Roberson
2018-9-20
KSSV
2018-9-20
YOu try the code, whic I gave. x will be an vector and answer will be a number as it is mean of x.
Isaac Osei Agyemang
2018-9-20
KSSV
2018-9-20
YOu mean mean(x)?
Isaac Osei Agyemang
2018-9-20
编辑:Walter Roberson
2018-9-20
类别
在 帮助中心 和 File Exchange 中查找有关 Matrix Computations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!