我需要对图中的非顺序节点索引实现splitapply函数。
我在具有非顺序聚类的图上实现了splitapply函数。返回簇的索引编号按顺序编号,但图顶点不按顺序编号。 我希望它返回原始图的确切节点索引。
S={' 1',' 1',' 2',' 6',' 6',' 8'};
T={' 2',' 3',' 3',' 8',' 9',' 9'};
weight=[2; 2; 2; 2; 2; 2];
G=graph(S,T,weight);
plot(G)
bins=conncomp(G);
clusters = splitapply(@(x) {x}, 1:numnodes(G), bins);
实际结果: clusters: [1,2,3];[4,5,6]
预期结果: clusters: [1,2,3];[6,8,9]
答案 0 :(得分:0)
输入代码后,尝试类似
nodes = table2array(G.Nodes);
result = cellfun(@(x) nodes(x), clusters, 'uniformoutput', false);