# How to build links between two graphs on the same figure?

8 ビュー (過去 30 日間)
Waseem AL Aqqad 2020 年 10 月 7 日
コメント済み: Waseem AL Aqqad 2020 年 10 月 7 日
Hi,
I am encountering a problem trying to simulate interdependent systems (graphs), I constructed and built two different graphs on the same figure, and now I'm trying to add interlinks (lines) between the graphs' different nodes. Could you kindly check my script below?
Thanks!
clear all;
%Edges of first Graph
s=[1 1 2 3 3 5];
t=[2 6 7 4 5 6];
%st=vertcat(s,t);
%Edges of Second Graph
e=[1 2 2 3 4 5 5 6];
r=[3 4 7 8 1 3 2 7];
%er=vertcat(e,r);
%Constructing the Graphs
h=graph(e,r);
g=graph(s,t,[]);
g.Nodes.Name={'1' '2' '3' '4' '5' '6' '7'}';
h.Nodes.Label={'source' 'target' 'Xuewei' 'Hassan' 'TAM' 'Muath' 'Alexander' 'Waseem'}';
%X and Y coordinates of two Graphs
x1 = [0 0.5 -0.5 -0.5 0.5 0 1.5];
y1 = [0 0.5 0.5 -0.5 -0.5 2 5 ];
x2=[1 1.5 0.5 0.5 1.5 2 2.5 3];
y2=[1 1.5 1.5 0 0 3 1.5 2];
%Plotting both graphs on the same figure
w=plot(g,'-dr','XData',x1,'YData',y1);
hold on
y=plot(h,'ko--','XData',x2,'YData',y2);
% labelnode(y,[1 2 3 4 5 6 7 8],{'source' 'target','Waseem' 'Hassan','Xuewei' 'Muath','Waseem' 'Alexander'})
datah=cat(1,w.XData,w.YData);
% plot(datah(:,1),datah(:,4),'k');
datag=cat(1,y.XData,y.YData);
line(datah(:,5),datag(:,6));
##### 3 件のコメント表示非表示 2 件の古いコメント
Waseem AL Aqqad 2020 年 10 月 7 日

サインインしてコメントする。

### 回答 (1 件)

Luciano Garim 2020 年 10 月 7 日
If your problem is only how to view these graphs together, you may proceed like this:
Create the G that is all connected. After, use subgraph to produce your g and h graphs.
I hope helped you!
##### 1 件のコメント表示非表示 なし
Waseem AL Aqqad 2020 年 10 月 7 日
Hi Luciano,
My mistake was not arranging the coordinates correctly

サインインしてコメントする。

### Community Treasure Hunt

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

Start Hunting!

Translated by