How can I generate a square lattice undirected graph?

14 visualizaciones (últimos 30 días)
Rayan Glus
Rayan Glus el 14 de Oct. de 2021
Comentada: Rayan Glus el 15 de Oct. de 2021
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 comentario
Rayan Glus
Rayan Glus el 14 de Oct. de 2021
Editada: Rayan Glus el 14 de Oct. de 2021
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?

Iniciar sesión para comentar.

Respuesta aceptada

Chunru
Chunru el 15 de Oct. de 2021
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

Más respuestas (0)

Categorías

Más información sobre Undirected Graphs en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by