Add Edges to Network Graph Without Changing the Layout

3 Ansichten (letzte 30 Tage)
Carson Bullock
Carson Bullock am 26 Sep. 2020
Bearbeitet: Carson Bullock am 26 Sep. 2020
I have two adjacency matrices that each contain the same nodes, but contain different edges. I can very easily plot these two graphs separately, or I can combine them, and plot them all together, but I'm having trouble combing them in the way that I want. I want the layout of the nodes to only reflect the edges contained in the first dataset, such that there locations do not take into account the second set of edges from the second adjacency matrix. Pics added for clarity, with the last one ("What I Want") faked in MS Paint. Code will read something like
%A1 = Adjacency Matrix 1, A2 = Adjacency Matrix 2
figure()
G1 = graph(A1)
G2 = graph(A2)
P1=plot(G1,'EdgeColor','k')
layout(P1,'force','usegravity',true)
G1=addedge(G1,G2.Edges)
highlight(P1,G2,'EdgeColor','b')
% This code fails because the edges that I am attempting to highlight do not exist in the plot P1.
% If I replot P1 after adding the edges from G2, then the layout changes.

Akzeptierte Antwort

Steven Lord
Steven Lord am 26 Sep. 2020
plot the first graph.
Turn hold on.
plot the second graph, specifying the XData, YData, and (if plotting the graph in 3D) ZData properties using the values of the XData, YData, and (if necessary) ZData properties of the first graph. See the "Custom Graph Node Coordinates" example on the documentation page for the graph plot function for an example setting those properties on a plotted graph.

Weitere Antworten (0)

Kategorien

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

Community Treasure Hunt

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

Start Hunting!

Translated by