How to build links between two graphs on the same figure?
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposte (1)
Luciano Garim
il 7 Ott 2020
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!
Vedere anche
Categorie
Scopri di più su Graph and Network Algorithms in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!