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

54 views (last 30 days)
Mariya B on 11 Apr 2016
Commented: Mariya B on 11 Apr 2016
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

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)];
plot(g,'XData',xdata,'YData',ydata) Mariya B on 11 Apr 2016
Thank you so much this works :)