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 Center および File ExchangeGraph and Network Algorithms についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by