Matlab函数的功能

问题描述 投票:0回答:2

这个问题与我以前的一个Matlab function to compute average neighbor degree有关

el = [2 1; 3 1;4 1;5 1;1 2 ]; %// 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

为了计算平均邻居度,可以构造另一个稀疏矩阵,其中邻居度存储在每个条目中

ndM = sparse( el(:,1), el(:,2), nd( el(:,2) ), n, n );

在上面的稀疏矩阵中,我理解它的功能。但是,我不明白nd(el(:,2)抛出的输出

你能指点我的资源吗?

matlab
2个回答
1
投票

没有资源可以指向。这是为您的特定应用程序定制的代码。顺便说一句,你没有完成整个故事。要计算每个节点的平均度数,您需要执行以下操作:

av = full( sum( ndM, 2 ) ./ nd );

在任何情况下,el都是您的边缘列表,其中第一列表示源节点,第二列是结束节点。 nd表示每个节点的程度。因此,通过做:

nd(el(:,2))

因此,您现在正在创建一个新图形,其中对于每对节点,这将包含边缘列表中结束节点的程度,这是您应该执行的操作。


0
投票

实际上,我在上一篇文章中得到了答案,as nd( el(:,2) )创建了一个所有相邻节点的(nd)度的向量(存储在el(:,2))中,这是@Shai在此帖子中给出的问题的解决方案Matlab expression

© www.soinside.com 2019 - 2024. All rights reserved.