Filter löschen
Filter löschen

Duplicate edges not supported after using unique

2 Ansichten (letzte 30 Tage)
Isaac Osei Agyemang
Isaac Osei Agyemang am 15 Okt. 2018
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 Kommentare
Guillaume
Guillaume am 15 Okt. 2018
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));
Isaac Osei Agyemang
Isaac Osei Agyemang am 16 Okt. 2018
Okay Guillaume, thanks you very much.

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Graph and Network Algorithms finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by