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

조회 수: 1 (최근 30일)
Waseem AL Aqqad
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'})
%Concatenation of XData and YData and add an interlink
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
Waseem AL Aqqad
Waseem AL Aqqad 2020년 10월 7일
I guess I figured it out.
node5=[datah(1,5) datag(1,6)];
node6=[datah(2,5),datag(2,6)];
plot(node5,node6);

댓글을 달려면 로그인하십시오.

답변 (1개)

Luciano Garim
Luciano Garim 2020년 10월 7일
Hi, Waseem AL Aqqad.
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
Waseem AL Aqqad 2020년 10월 7일
Hi Luciano,
Thanks for your reply!
My mistake was not arranging the coordinates correctly

댓글을 달려면 로그인하십시오.

카테고리

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