我想在 MATLAB 中创建一个随机邻接矩阵,使得权重总和等于边数。最后找到拉普拉斯矩阵使用
L = diag(sum(A)) - A
然后绘制它。有什么办法吗? 提前致谢。
最佳答案
无向图的邻接矩阵只是一个方对称矩阵。
如果你对节点的度数没有限制,只在权重上,我会建议类似的东西
n ; % number of nodes in the graph
density = 1e-3; % a rough estimate of the amount of edges
A = sprand( n, n, density ); % generate adjacency matrix at random
% normalize weights to sum to num of edges
A = tril( A, -1 );
A = spfun( @(x) x./nnz(A), A );
% make it symmetric (for undirected graph)
A = A + A.';
我在这段代码中使用了:
关于matlab - 在 MATLAB 中生成随机加权邻接矩阵,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14684966/