Create a n*n grid undirected graph
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi all, I can't figure out how I can solve this problem. I'm working with undirected graph in matlab. I created graph with 15 nodes with this code:
s = [1 1 1 2 2 2 2 3 3 3 3 4 4 4 4 4 5 5 5 6 8 10 2 11 7 8 10 13 10 11 13 15];
t = [2 6 7 3 6 7 8 4 7 8 9 5 8 9 10 13 9 10 11 14 13 11 14 12 9 14 13 15 15 15 14 12];
G = graph(s,t);
I now need to create a graph with 100 nodes in a grid shape. Something like the picture below:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/789480/image.png)
Whit this code:
grid=reshape(1:100,10,10)';
grid =
1 2 3 4 5 6 7 8 9 10
11 12 13 14 15 16 17 18 19 20
21 22 23 24 25 26 27 28 29 30
31 32 33 34 35 36 37 38 39 40
41 42 43 44 45 46 47 48 49 50
51 52 53 54 55 56 57 58 59 60
61 62 63 64 65 66 67 68 69 70
71 72 73 74 75 76 77 78 79 80
81 82 83 84 85 86 87 88 89 90
91 92 93 94 95 96 97 98 99 100
I'm able to create a grid of number but how can I trasform this into a graph like the previous pictures?
0 comentarios
Respuestas (1)
KSSV
el 4 de Nov. de 2021
[x,y] = meshgrid(1:10) ;
dt = delaunayTriangulation(x(:),y(:)) ;
triplot(dt)
2 comentarios
Ver también
Categorías
Más información sobre Directed 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!