Is there a method to create a graph using adjacency matrix and plot the graph using custom coordinates.

33 views (last 30 days)
Hello All, There is an example where we can create a network using graph(s,t,weights) and plotting it by using plot (G,'XData',x_coordinate,'YData',y_coordinate). Has anyone tried creating a graph using a sparse adjacency matrix graph(A,omitselfloops) and then plotting it using plot (G,'XData',x_coordinate,'YData',y_coordinate). Thanks in advance

Accepted Answer

Mike Garrity
Mike Garrity on 11 Apr 2016
The answer I gave to this MATLAB Answers question does that. In that case, I set the XData & YData after the call to plot. But you could easily rewrite it to work the way you suggested:
% Make a random MxN adjacency matrix
m = 3
n = 5
a = rand(m,n)>.25;
% Expand out to symmetric (M+N)x(M+N) matrix
big_a = [zeros(m,m), a;
a', zeros(n,n)];
g = graph(big_a);
xdata = [ones(1,m), 2+zeros(1,n)];
ydata = [linspace(0,1,m), linspace(0,1,n)];

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by