在 Matlab 中,如何删除有向图中没有边的节点?

In Matlab, how can I remove nodes with no edges in a directed graph?

我输入这个:

plot(digraph([1 2 3 10],[2 3 1 1]))

而图中显示

如何删除节点 8、9、4、5、6 和 7?是否有设置不显示任何没有边的节点?[​​=12=]

您可以使用 unique, so that there are no holes in the list of node numbers. To maintain the original node names, pass them as fourth input to digraph 以字符串元胞数组的形式手动重新标记边缘:

S = [1 2 3 10];
T = [2 3 1 1];
[u, ~, w] = unique([S T]);
plot(digraph(w(1:end/2), w(end/2+1:end), [], cellstr(num2str(u.'))))