Duplicate edges not supported after using unique

2 次查看(过去 30 天)
Hello community, I'm comparing two graphs, I'm able to plot the first graph fine and afterwards i sort the data in the table to replot the secod graph. I use unique to eliminate any duplicate rows in order not for the error duplicate edges not supported to show up but for some reasons it still throw the error duplicate edges not supported. Code is below:
a = 1:2637;
NewEdge(a,1) = sort(NewEdge(a,1));
b = 1:2637;
NewEdge(b,2) = sort(NewEdge(b,2),'descend');
%NewEdge(:,1:2) = sort(NewEdge(:,1:2));
NewEdge = unique(NewEdge(:,1:2),'rows'); %eliminate duplicates
GG = graph(NewEdge(:,1), NewEdge(:,2)); % create a graph from A
d = degree(GG);
notConnected = find(d < 2); % weakly connected nodes
d(notConnected) = []; % drop them from deg
GG = rmnode(GG, notConnected); % drop them from graph
figure % visualize the graph
plot(GG);
title('Power Grid, After movement')
  2 个评论
Guillaume
Guillaume 2018-10-15
Which function throws your duplicate edge not supported error? plot has no problem plotting graphs with duplicate edges.
Note that if you want to remove duplicate edges in a graph, the simplest way to do that is:
%remove duplicate edges from graph g
g = graph(unique(g.Edges));

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Graph and Network Algorithms 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by