259 views (last 30 days)

Show older comments

I'm trying to connect the nodes of graph g (Blue) with the nodes of graph h (Red).

so=[1 1 1 2 2 2 2 3 3 3 5];

ta=[2 3 4 3 4 5 6 6 7 5 7];

g=graph(so,ta);

p=plot(g);

x=p.XData;

y=p.YData;

z2=[0 0 0 0 0 0 0];

subplot(2,2,1);plot(g,'XData',x,'YData',y,'ZData',z2)

s=[1 1 1 2 2 3 3 3 3 4 4 5 5 ];

t=[2 5 6 3 4 7 4 5 6 7 5 7 6 ];

h=graph(s,t);

z=[-3 -3 -3 -3 -3 -3 -3];

hold on; subplot(2,2,1);plot(h,'XData',x,'YData',y,'ZData',z)

Is it something doable?

Thank you all for your continuous support!

Christine Tobler
on 18 Jan 2021

You could also add the edges of both graphs to one larger graph, and then use addedge to connect them. You would probably not get a clear separation visually of what used to be the first graph and the second graph this way, though.

so=[1 1 1 2 2 2 2 3 3 3 5];

ta=[2 3 4 3 4 5 6 6 7 5 7];

g=graph(so,ta);

p=plot(g);

x=p.XData;

y=p.YData;

z2=[0 0 0 0 0 0 0];

s=[1 1 1 2 2 3 3 3 3 4 4 5 5 ];

t=[2 5 6 3 4 7 4 5 6 7 5 7 6 ];

h=graph(s,t);

z=[-3 -3 -3 -3 -3 -3 -3];

gh = graph([so, s+7], [ta, t+7])

gh = addedge(gh, 2, 4+7)

plot(gh,'XData',[x, x],'YData',[y, y],'ZData',[z2, z2-3])

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

Start Hunting!