Add Edges to Network Graph Without Changing the Layout

조회 수: 3 (최근 30일)
Carson Bullock
Carson Bullock 2020년 9월 26일
편집: Carson Bullock 2020년 9월 26일
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.

채택된 답변

Steven Lord
Steven Lord 2020년 9월 26일
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.

추가 답변 (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