How can I generate a square lattice undirected graph?

22 次查看(过去 30 天)
Hi,
How can I generate a square lattice undirected graph? I tried this:
n = 10;
A = delsq(numgrid('S',n+2));
G = graph(A,'omitselfloops');
plot(G)
But the links do not look straight, right? And the graph looks like a plateau.
Thanks!
  1 个评论
Rayan Glus
Rayan Glus 2021-10-14
编辑:Rayan Glus 2021-10-14
Okay, when I checked the XData and YData using :
p = plot(G);
p.XData
p.YData
I found that nodes are not evenly spaced. Can you help me on this please?

请先登录,再进行评论。

采纳的回答

Chunru
Chunru 2021-10-15
n = 10;
A = delsq(numgrid('S',n+2));
G = graph(A,'omitselfloops');
h = plot(G);
h.XData = floor((0:99)/10);
h.YData = rem((0:99), 10);
axis equal

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Undirected Graphs 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by