0

我正在将 Graphviz 用于 matlab。有没有办法删除最终图中没有边的节点,因为我的图非常大(~9100 个节点),并且以更好的方式表示图的任何其他帮助将不胜感激。

4

1 回答 1

1

的输入graphviz邻接矩阵,因此您可以执行以下操作:

% Generate random adjacency matrix with no nodes connected to themselves
N = 10; 
adj = (randi(N, N) > 5) .* (ones(N) - eye(N));

% Spuriously set one row and column to zero: no connections for this node
adj(:, 2) = 0; adj(2, :) = 0;

% Find the nodes with no edges
noEdgeNodes = all(adj == 0, 1) & all(adj == 0, 2)'

noEdgeNodes =

 0     1     0     0     0     0     0     0     0     0

% Remove nodes with no edges
adj(noEdgeNodes, :) = []; 
adj(:, noEdgeNodes) = [];

% Call graphviz
graphViz4Matlab('-adjMat', adj, '-nodeLabels', ...
    arrayfun(@(x){num2str(x)}, 1:size(adj, 1)))
于 2013-04-12T13:43:50.757 回答