Meshgrid to be used for hexagons

54 Ansichten (letzte 30 Tage)
Nupur
Nupur am 16 Jun. 2023
Bearbeitet: Bruno Luong am 28 Jun. 2023
I want to use meshgrid for generating a hexagonal grid. Also I should get the cooridntes of each node in it.
  1 Kommentar
Angelo Yeo
Angelo Yeo am 16 Jun. 2023
You can refer to the comment in the URL below.
https://www.mathworks.com/matlabcentral/answers/284805-create-hexagonal-grid-with-a-central-cell

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Subhajyoti Halder
Subhajyoti Halder am 28 Jun. 2023
Hi Nupur,
It is my understanding, it is required to use meshgrid to generate a hexagonal grid and get the cooridntes of each node in it.
Here, I have implemented it using ‘meshgrid()’ in MATLAB R2023a.
In the below code,it is using the meshgrid function within a loop to generate the x and y coordinates for each row of the grid.
% Define the parameters of the hexagonal grid
% radius: radius of the hexagon
radius = 5;
% Number of rows in the grid
numRows = 10;
% Generate the x and y coordinates of the hexagonal grid
x = [];
y = [];
for row = 1:numRows
% xOffset, yOffset: variables to shift the coordinates of each row
% to form a hexagonal pattern.
xOffset = (mod(row, 2) * sqrt(3) / 2) * radius;
yOffset = row * (3 / 2) * radius;
% meshgrid() generates the x,y coordinates for each row of the grid.
[xRow, yRow] = meshgrid(0:radius*sqrt(3), 0:2*radius);
xRow = xRow(:)' + xOffset;
yRow = yRow(:)' + yOffset;
x = [x, xRow];
y = [y, yRow];
end
% Display the coordinates of each node in the hexagonal grid
for i = 1:numel(x)
fprintf('Node %d: (%.2f, %.2f)\n', i, x(i), y(i));
end
Node 1: (4.33, 7.50) Node 2: (4.33, 8.50) Node 3: (4.33, 9.50) Node 4: (4.33, 10.50) Node 5: (4.33, 11.50) Node 6: (4.33, 12.50) Node 7: (4.33, 13.50) Node 8: (4.33, 14.50) Node 9: (4.33, 15.50) Node 10: (4.33, 16.50) Node 11: (4.33, 17.50) Node 12: (5.33, 7.50) Node 13: (5.33, 8.50) Node 14: (5.33, 9.50) Node 15: (5.33, 10.50) Node 16: (5.33, 11.50) Node 17: (5.33, 12.50) Node 18: (5.33, 13.50) Node 19: (5.33, 14.50) Node 20: (5.33, 15.50) Node 21: (5.33, 16.50) Node 22: (5.33, 17.50) Node 23: (6.33, 7.50) Node 24: (6.33, 8.50) Node 25: (6.33, 9.50) Node 26: (6.33, 10.50) Node 27: (6.33, 11.50) Node 28: (6.33, 12.50) Node 29: (6.33, 13.50) Node 30: (6.33, 14.50) Node 31: (6.33, 15.50) Node 32: (6.33, 16.50) Node 33: (6.33, 17.50) Node 34: (7.33, 7.50) Node 35: (7.33, 8.50) Node 36: (7.33, 9.50) Node 37: (7.33, 10.50) Node 38: (7.33, 11.50) Node 39: (7.33, 12.50) Node 40: (7.33, 13.50) Node 41: (7.33, 14.50) Node 42: (7.33, 15.50) Node 43: (7.33, 16.50) Node 44: (7.33, 17.50) Node 45: (8.33, 7.50) Node 46: (8.33, 8.50) Node 47: (8.33, 9.50) Node 48: (8.33, 10.50) Node 49: (8.33, 11.50) Node 50: (8.33, 12.50) Node 51: (8.33, 13.50) Node 52: (8.33, 14.50) Node 53: (8.33, 15.50) Node 54: (8.33, 16.50) Node 55: (8.33, 17.50) Node 56: (9.33, 7.50) Node 57: (9.33, 8.50) Node 58: (9.33, 9.50) Node 59: (9.33, 10.50) Node 60: (9.33, 11.50) Node 61: (9.33, 12.50) Node 62: (9.33, 13.50) Node 63: (9.33, 14.50) Node 64: (9.33, 15.50) Node 65: (9.33, 16.50) Node 66: (9.33, 17.50) Node 67: (10.33, 7.50) Node 68: (10.33, 8.50) Node 69: (10.33, 9.50) Node 70: (10.33, 10.50) Node 71: (10.33, 11.50) Node 72: (10.33, 12.50) Node 73: (10.33, 13.50) Node 74: (10.33, 14.50) Node 75: (10.33, 15.50) Node 76: (10.33, 16.50) Node 77: (10.33, 17.50) Node 78: (11.33, 7.50) Node 79: (11.33, 8.50) Node 80: (11.33, 9.50) Node 81: (11.33, 10.50) Node 82: (11.33, 11.50) Node 83: (11.33, 12.50) Node 84: (11.33, 13.50) Node 85: (11.33, 14.50) Node 86: (11.33, 15.50) Node 87: (11.33, 16.50) Node 88: (11.33, 17.50) Node 89: (12.33, 7.50) Node 90: (12.33, 8.50) Node 91: (12.33, 9.50) Node 92: (12.33, 10.50) Node 93: (12.33, 11.50) Node 94: (12.33, 12.50) Node 95: (12.33, 13.50) Node 96: (12.33, 14.50) Node 97: (12.33, 15.50) Node 98: (12.33, 16.50) Node 99: (12.33, 17.50) Node 100: (0.00, 15.00) Node 101: (0.00, 16.00) Node 102: (0.00, 17.00) Node 103: (0.00, 18.00) Node 104: (0.00, 19.00) Node 105: (0.00, 20.00) Node 106: (0.00, 21.00) Node 107: (0.00, 22.00) Node 108: (0.00, 23.00) Node 109: (0.00, 24.00) Node 110: (0.00, 25.00) Node 111: (1.00, 15.00) Node 112: (1.00, 16.00) Node 113: (1.00, 17.00) Node 114: (1.00, 18.00) Node 115: (1.00, 19.00) Node 116: (1.00, 20.00) Node 117: (1.00, 21.00) Node 118: (1.00, 22.00) Node 119: (1.00, 23.00) Node 120: (1.00, 24.00) Node 121: (1.00, 25.00) Node 122: (2.00, 15.00) Node 123: (2.00, 16.00) Node 124: (2.00, 17.00) Node 125: (2.00, 18.00) Node 126: (2.00, 19.00) Node 127: (2.00, 20.00) Node 128: (2.00, 21.00) Node 129: (2.00, 22.00) Node 130: (2.00, 23.00) Node 131: (2.00, 24.00) Node 132: (2.00, 25.00) Node 133: (3.00, 15.00) Node 134: (3.00, 16.00) Node 135: (3.00, 17.00) Node 136: (3.00, 18.00) Node 137: (3.00, 19.00) Node 138: (3.00, 20.00) Node 139: (3.00, 21.00) Node 140: (3.00, 22.00) Node 141: (3.00, 23.00) Node 142: (3.00, 24.00) Node 143: (3.00, 25.00) Node 144: (4.00, 15.00) Node 145: (4.00, 16.00) Node 146: (4.00, 17.00) Node 147: (4.00, 18.00) Node 148: (4.00, 19.00) Node 149: (4.00, 20.00) Node 150: (4.00, 21.00) Node 151: (4.00, 22.00) Node 152: (4.00, 23.00) Node 153: (4.00, 24.00) Node 154: (4.00, 25.00) Node 155: (5.00, 15.00) Node 156: (5.00, 16.00) Node 157: (5.00, 17.00) Node 158: (5.00, 18.00) Node 159: (5.00, 19.00) Node 160: (5.00, 20.00) Node 161: (5.00, 21.00) Node 162: (5.00, 22.00) Node 163: (5.00, 23.00) Node 164: (5.00, 24.00) Node 165: (5.00, 25.00) Node 166: (6.00, 15.00) Node 167: (6.00, 16.00) Node 168: (6.00, 17.00) Node 169: (6.00, 18.00) Node 170: (6.00, 19.00) Node 171: (6.00, 20.00) Node 172: (6.00, 21.00) Node 173: (6.00, 22.00) Node 174: (6.00, 23.00) Node 175: (6.00, 24.00) Node 176: (6.00, 25.00) Node 177: (7.00, 15.00) Node 178: (7.00, 16.00) Node 179: (7.00, 17.00) Node 180: (7.00, 18.00) Node 181: (7.00, 19.00) Node 182: (7.00, 20.00) Node 183: (7.00, 21.00) Node 184: (7.00, 22.00) Node 185: (7.00, 23.00) Node 186: (7.00, 24.00) Node 187: (7.00, 25.00) Node 188: (8.00, 15.00) Node 189: (8.00, 16.00) Node 190: (8.00, 17.00) Node 191: (8.00, 18.00) Node 192: (8.00, 19.00) Node 193: (8.00, 20.00) Node 194: (8.00, 21.00) Node 195: (8.00, 22.00) Node 196: (8.00, 23.00) Node 197: (8.00, 24.00) Node 198: (8.00, 25.00) Node 199: (4.33, 22.50) Node 200: (4.33, 23.50) Node 201: (4.33, 24.50) Node 202: (4.33, 25.50) Node 203: (4.33, 26.50) Node 204: (4.33, 27.50) Node 205: (4.33, 28.50) Node 206: (4.33, 29.50) Node 207: (4.33, 30.50) Node 208: (4.33, 31.50) Node 209: (4.33, 32.50) Node 210: (5.33, 22.50) Node 211: (5.33, 23.50) Node 212: (5.33, 24.50) Node 213: (5.33, 25.50) Node 214: (5.33, 26.50) Node 215: (5.33, 27.50) Node 216: (5.33, 28.50) Node 217: (5.33, 29.50) Node 218: (5.33, 30.50) Node 219: (5.33, 31.50) Node 220: (5.33, 32.50) Node 221: (6.33, 22.50) Node 222: (6.33, 23.50) Node 223: (6.33, 24.50) Node 224: (6.33, 25.50) Node 225: (6.33, 26.50) Node 226: (6.33, 27.50) Node 227: (6.33, 28.50) Node 228: (6.33, 29.50) Node 229: (6.33, 30.50) Node 230: (6.33, 31.50) Node 231: (6.33, 32.50) Node 232: (7.33, 22.50) Node 233: (7.33, 23.50) Node 234: (7.33, 24.50) Node 235: (7.33, 25.50) Node 236: (7.33, 26.50) Node 237: (7.33, 27.50) Node 238: (7.33, 28.50) Node 239: (7.33, 29.50) Node 240: (7.33, 30.50) Node 241: (7.33, 31.50) Node 242: (7.33, 32.50) Node 243: (8.33, 22.50) Node 244: (8.33, 23.50) Node 245: (8.33, 24.50) Node 246: (8.33, 25.50) Node 247: (8.33, 26.50) Node 248: (8.33, 27.50) Node 249: (8.33, 28.50) Node 250: (8.33, 29.50) Node 251: (8.33, 30.50) Node 252: (8.33, 31.50) Node 253: (8.33, 32.50) Node 254: (9.33, 22.50) Node 255: (9.33, 23.50) Node 256: (9.33, 24.50) Node 257: (9.33, 25.50) Node 258: (9.33, 26.50) Node 259: (9.33, 27.50) Node 260: (9.33, 28.50) Node 261: (9.33, 29.50) Node 262: (9.33, 30.50) Node 263: (9.33, 31.50) Node 264: (9.33, 32.50) Node 265: (10.33, 22.50) Node 266: (10.33, 23.50) Node 267: (10.33, 24.50) Node 268: (10.33, 25.50) Node 269: (10.33, 26.50) Node 270: (10.33, 27.50) Node 271: (10.33, 28.50) Node 272: (10.33, 29.50) Node 273: (10.33, 30.50) Node 274: (10.33, 31.50) Node 275: (10.33, 32.50) Node 276: (11.33, 22.50) Node 277: (11.33, 23.50) Node 278: (11.33, 24.50) Node 279: (11.33, 25.50) Node 280: (11.33, 26.50) Node 281: (11.33, 27.50) Node 282: (11.33, 28.50) Node 283: (11.33, 29.50) Node 284: (11.33, 30.50) Node 285: (11.33, 31.50) Node 286: (11.33, 32.50) Node 287: (12.33, 22.50) Node 288: (12.33, 23.50) Node 289: (12.33, 24.50) Node 290: (12.33, 25.50) Node 291: (12.33, 26.50) Node 292: (12.33, 27.50) Node 293: (12.33, 28.50) Node 294: (12.33, 29.50) Node 295: (12.33, 30.50) Node 296: (12.33, 31.50) Node 297: (12.33, 32.50) Node 298: (0.00, 30.00) Node 299: (0.00, 31.00) Node 300: (0.00, 32.00) Node 301: (0.00, 33.00) Node 302: (0.00, 34.00) Node 303: (0.00, 35.00) Node 304: (0.00, 36.00) Node 305: (0.00, 37.00) Node 306: (0.00, 38.00) Node 307: (0.00, 39.00) Node 308: (0.00, 40.00) Node 309: (1.00, 30.00) Node 310: (1.00, 31.00) Node 311: (1.00, 32.00) Node 312: (1.00, 33.00) Node 313: (1.00, 34.00) Node 314: (1.00, 35.00) Node 315: (1.00, 36.00) Node 316: (1.00, 37.00) Node 317: (1.00, 38.00) Node 318: (1.00, 39.00) Node 319: (1.00, 40.00) Node 320: (2.00, 30.00) Node 321: (2.00, 31.00) Node 322: (2.00, 32.00) Node 323: (2.00, 33.00) Node 324: (2.00, 34.00) Node 325: (2.00, 35.00) Node 326: (2.00, 36.00) Node 327: (2.00, 37.00) Node 328: (2.00, 38.00) Node 329: (2.00, 39.00) Node 330: (2.00, 40.00) Node 331: (3.00, 30.00) Node 332: (3.00, 31.00) Node 333: (3.00, 32.00) Node 334: (3.00, 33.00) Node 335: (3.00, 34.00) Node 336: (3.00, 35.00) Node 337: (3.00, 36.00) Node 338: (3.00, 37.00) Node 339: (3.00, 38.00) Node 340: (3.00, 39.00) Node 341: (3.00, 40.00) Node 342: (4.00, 30.00) Node 343: (4.00, 31.00) Node 344: (4.00, 32.00) Node 345: (4.00, 33.00) Node 346: (4.00, 34.00) Node 347: (4.00, 35.00) Node 348: (4.00, 36.00) Node 349: (4.00, 37.00) Node 350: (4.00, 38.00) Node 351: (4.00, 39.00) Node 352: (4.00, 40.00) Node 353: (5.00, 30.00) Node 354: (5.00, 31.00) Node 355: (5.00, 32.00) Node 356: (5.00, 33.00) Node 357: (5.00, 34.00) Node 358: (5.00, 35.00) Node 359: (5.00, 36.00) Node 360: (5.00, 37.00) Node 361: (5.00, 38.00) Node 362: (5.00, 39.00) Node 363: (5.00, 40.00) Node 364: (6.00, 30.00) Node 365: (6.00, 31.00) Node 366: (6.00, 32.00) Node 367: (6.00, 33.00) Node 368: (6.00, 34.00) Node 369: (6.00, 35.00) Node 370: (6.00, 36.00) Node 371: (6.00, 37.00) Node 372: (6.00, 38.00) Node 373: (6.00, 39.00) Node 374: (6.00, 40.00) Node 375: (7.00, 30.00) Node 376: (7.00, 31.00) Node 377: (7.00, 32.00) Node 378: (7.00, 33.00) Node 379: (7.00, 34.00) Node 380: (7.00, 35.00) Node 381: (7.00, 36.00) Node 382: (7.00, 37.00) Node 383: (7.00, 38.00) Node 384: (7.00, 39.00) Node 385: (7.00, 40.00) Node 386: (8.00, 30.00) Node 387: (8.00, 31.00) Node 388: (8.00, 32.00) Node 389: (8.00, 33.00) Node 390: (8.00, 34.00) Node 391: (8.00, 35.00) Node 392: (8.00, 36.00) Node 393: (8.00, 37.00) Node 394: (8.00, 38.00) Node 395: (8.00, 39.00) Node 396: (8.00, 40.00) Node 397: (4.33, 37.50) Node 398: (4.33, 38.50) Node 399: (4.33, 39.50) Node 400: (4.33, 40.50) Node 401: (4.33, 41.50) Node 402: (4.33, 42.50) Node 403: (4.33, 43.50) Node 404: (4.33, 44.50) Node 405: (4.33, 45.50) Node 406: (4.33, 46.50) Node 407: (4.33, 47.50) Node 408: (5.33, 37.50) Node 409: (5.33, 38.50) Node 410: (5.33, 39.50) Node 411: (5.33, 40.50) Node 412: (5.33, 41.50) Node 413: (5.33, 42.50) Node 414: (5.33, 43.50) Node 415: (5.33, 44.50) Node 416: (5.33, 45.50) Node 417: (5.33, 46.50) Node 418: (5.33, 47.50) Node 419: (6.33, 37.50) Node 420: (6.33, 38.50) Node 421: (6.33, 39.50) Node 422: (6.33, 40.50) Node 423: (6.33, 41.50) Node 424: (6.33, 42.50) Node 425: (6.33, 43.50) Node 426: (6.33, 44.50) Node 427: (6.33, 45.50) Node 428: (6.33, 46.50) Node 429: (6.33, 47.50) Node 430: (7.33, 37.50) Node 431: (7.33, 38.50) Node 432: (7.33, 39.50) Node 433: (7.33, 40.50) Node 434: (7.33, 41.50) Node 435: (7.33, 42.50) Node 436: (7.33, 43.50) Node 437: (7.33, 44.50) Node 438: (7.33, 45.50) Node 439: (7.33, 46.50) Node 440: (7.33, 47.50) Node 441: (8.33, 37.50) Node 442: (8.33, 38.50) Node 443: (8.33, 39.50) Node 444: (8.33, 40.50) Node 445: (8.33, 41.50) Node 446: (8.33, 42.50) Node 447: (8.33, 43.50) Node 448: (8.33, 44.50) Node 449: (8.33, 45.50) Node 450: (8.33, 46.50) Node 451: (8.33, 47.50) Node 452: (9.33, 37.50) Node 453: (9.33, 38.50) Node 454: (9.33, 39.50) Node 455: (9.33, 40.50) Node 456: (9.33, 41.50) Node 457: (9.33, 42.50) Node 458: (9.33, 43.50) Node 459: (9.33, 44.50) Node 460: (9.33, 45.50) Node 461: (9.33, 46.50) Node 462: (9.33, 47.50) Node 463: (10.33, 37.50) Node 464: (10.33, 38.50) Node 465: (10.33, 39.50) Node 466: (10.33, 40.50) Node 467: (10.33, 41.50) Node 468: (10.33, 42.50) Node 469: (10.33, 43.50) Node 470: (10.33, 44.50) Node 471: (10.33, 45.50) Node 472: (10.33, 46.50) Node 473: (10.33, 47.50) Node 474: (11.33, 37.50) Node 475: (11.33, 38.50) Node 476: (11.33, 39.50) Node 477: (11.33, 40.50) Node 478: (11.33, 41.50) Node 479: (11.33, 42.50) Node 480: (11.33, 43.50) Node 481: (11.33, 44.50) Node 482: (11.33, 45.50) Node 483: (11.33, 46.50) Node 484: (11.33, 47.50) Node 485: (12.33, 37.50) Node 486: (12.33, 38.50) Node 487: (12.33, 39.50) Node 488: (12.33, 40.50) Node 489: (12.33, 41.50) Node 490: (12.33, 42.50) Node 491: (12.33, 43.50) Node 492: (12.33, 44.50) Node 493: (12.33, 45.50) Node 494: (12.33, 46.50) Node 495: (12.33, 47.50) Node 496: (0.00, 45.00) Node 497: (0.00, 46.00) Node 498: (0.00, 47.00) Node 499: (0.00, 48.00) Node 500: (0.00, 49.00) Node 501: (0.00, 50.00) Node 502: (0.00, 51.00) Node 503: (0.00, 52.00) Node 504: (0.00, 53.00) Node 505: (0.00, 54.00) Node 506: (0.00, 55.00) Node 507: (1.00, 45.00) Node 508: (1.00, 46.00) Node 509: (1.00, 47.00) Node 510: (1.00, 48.00) Node 511: (1.00, 49.00) Node 512: (1.00, 50.00) Node 513: (1.00, 51.00) Node 514: (1.00, 52.00) Node 515: (1.00, 53.00) Node 516: (1.00, 54.00) Node 517: (1.00, 55.00) Node 518: (2.00, 45.00) Node 519: (2.00, 46.00) Node 520: (2.00, 47.00) Node 521: (2.00, 48.00) Node 522: (2.00, 49.00) Node 523: (2.00, 50.00) Node 524: (2.00, 51.00) Node 525: (2.00, 52.00) Node 526: (2.00, 53.00) Node 527: (2.00, 54.00) Node 528: (2.00, 55.00) Node 529: (3.00, 45.00) Node 530: (3.00, 46.00) Node 531: (3.00, 47.00) Node 532: (3.00, 48.00) Node 533: (3.00, 49.00) Node 534: (3.00, 50.00) Node 535: (3.00, 51.00) Node 536: (3.00, 52.00) Node 537: (3.00, 53.00) Node 538: (3.00, 54.00) Node 539: (3.00, 55.00) Node 540: (4.00, 45.00) Node 541: (4.00, 46.00) Node 542: (4.00, 47.00) Node 543: (4.00, 48.00) Node 544: (4.00, 49.00) Node 545: (4.00, 50.00) Node 546: (4.00, 51.00) Node 547: (4.00, 52.00) Node 548: (4.00, 53.00) Node 549: (4.00, 54.00) Node 550: (4.00, 55.00) Node 551: (5.00, 45.00) Node 552: (5.00, 46.00) Node 553: (5.00, 47.00) Node 554: (5.00, 48.00) Node 555: (5.00, 49.00) Node 556: (5.00, 50.00) Node 557: (5.00, 51.00) Node 558: (5.00, 52.00) Node 559: (5.00, 53.00) Node 560: (5.00, 54.00) Node 561: (5.00, 55.00) Node 562: (6.00, 45.00) Node 563: (6.00, 46.00) Node 564: (6.00, 47.00) Node 565: (6.00, 48.00) Node 566: (6.00, 49.00) Node 567: (6.00, 50.00) Node 568: (6.00, 51.00) Node 569: (6.00, 52.00) Node 570: (6.00, 53.00) Node 571: (6.00, 54.00) Node 572: (6.00, 55.00) Node 573: (7.00, 45.00) Node 574: (7.00, 46.00) Node 575: (7.00, 47.00) Node 576: (7.00, 48.00) Node 577: (7.00, 49.00) Node 578: (7.00, 50.00) Node 579: (7.00, 51.00) Node 580: (7.00, 52.00) Node 581: (7.00, 53.00) Node 582: (7.00, 54.00) Node 583: (7.00, 55.00) Node 584: (8.00, 45.00) Node 585: (8.00, 46.00) Node 586: (8.00, 47.00) Node 587: (8.00, 48.00) Node 588: (8.00, 49.00) Node 589: (8.00, 50.00) Node 590: (8.00, 51.00) Node 591: (8.00, 52.00) Node 592: (8.00, 53.00) Node 593: (8.00, 54.00) Node 594: (8.00, 55.00) Node 595: (4.33, 52.50) Node 596: (4.33, 53.50) Node 597: (4.33, 54.50) Node 598: (4.33, 55.50) Node 599: (4.33, 56.50) Node 600: (4.33, 57.50) Node 601: (4.33, 58.50) Node 602: (4.33, 59.50) Node 603: (4.33, 60.50) Node 604: (4.33, 61.50) Node 605: (4.33, 62.50) Node 606: (5.33, 52.50) Node 607: (5.33, 53.50) Node 608: (5.33, 54.50) Node 609: (5.33, 55.50) Node 610: (5.33, 56.50) Node 611: (5.33, 57.50) Node 612: (5.33, 58.50) Node 613: (5.33, 59.50) Node 614: (5.33, 60.50) Node 615: (5.33, 61.50) Node 616: (5.33, 62.50) Node 617: (6.33, 52.50) Node 618: (6.33, 53.50) Node 619: (6.33, 54.50) Node 620: (6.33, 55.50) Node 621: (6.33, 56.50) Node 622: (6.33, 57.50) Node 623: (6.33, 58.50) Node 624: (6.33, 59.50) Node 625: (6.33, 60.50) Node 626: (6.33, 61.50) Node 627: (6.33, 62.50) Node 628: (7.33, 52.50) Node 629: (7.33, 53.50) Node 630: (7.33, 54.50) Node 631: (7.33, 55.50) Node 632: (7.33, 56.50) Node 633: (7.33, 57.50) Node 634: (7.33, 58.50) Node 635: (7.33, 59.50) Node 636: (7.33, 60.50) Node 637: (7.33, 61.50) Node 638: (7.33, 62.50) Node 639: (8.33, 52.50) Node 640: (8.33, 53.50) Node 641: (8.33, 54.50) Node 642: (8.33, 55.50) Node 643: (8.33, 56.50) Node 644: (8.33, 57.50) Node 645: (8.33, 58.50) Node 646: (8.33, 59.50) Node 647: (8.33, 60.50) Node 648: (8.33, 61.50) Node 649: (8.33, 62.50) Node 650: (9.33, 52.50) Node 651: (9.33, 53.50) Node 652: (9.33, 54.50) Node 653: (9.33, 55.50) Node 654: (9.33, 56.50) Node 655: (9.33, 57.50) Node 656: (9.33, 58.50) Node 657: (9.33, 59.50) Node 658: (9.33, 60.50) Node 659: (9.33, 61.50) Node 660: (9.33, 62.50) Node 661: (10.33, 52.50) Node 662: (10.33, 53.50) Node 663: (10.33, 54.50) Node 664: (10.33, 55.50) Node 665: (10.33, 56.50) Node 666: (10.33, 57.50) Node 667: (10.33, 58.50) Node 668: (10.33, 59.50) Node 669: (10.33, 60.50) Node 670: (10.33, 61.50) Node 671: (10.33, 62.50) Node 672: (11.33, 52.50) Node 673: (11.33, 53.50) Node 674: (11.33, 54.50) Node 675: (11.33, 55.50) Node 676: (11.33, 56.50) Node 677: (11.33, 57.50) Node 678: (11.33, 58.50) Node 679: (11.33, 59.50) Node 680: (11.33, 60.50) Node 681: (11.33, 61.50) Node 682: (11.33, 62.50) Node 683: (12.33, 52.50) Node 684: (12.33, 53.50) Node 685: (12.33, 54.50) Node 686: (12.33, 55.50) Node 687: (12.33, 56.50) Node 688: (12.33, 57.50) Node 689: (12.33, 58.50) Node 690: (12.33, 59.50) Node 691: (12.33, 60.50) Node 692: (12.33, 61.50) Node 693: (12.33, 62.50) Node 694: (0.00, 60.00) Node 695: (0.00, 61.00) Node 696: (0.00, 62.00) Node 697: (0.00, 63.00) Node 698: (0.00, 64.00) Node 699: (0.00, 65.00) Node 700: (0.00, 66.00) Node 701: (0.00, 67.00) Node 702: (0.00, 68.00) Node 703: (0.00, 69.00) Node 704: (0.00, 70.00) Node 705: (1.00, 60.00) Node 706: (1.00, 61.00) Node 707: (1.00, 62.00) Node 708: (1.00, 63.00) Node 709: (1.00, 64.00) Node 710: (1.00, 65.00) Node 711: (1.00, 66.00) Node 712: (1.00, 67.00) Node 713: (1.00, 68.00) Node 714: (1.00, 69.00) Node 715: (1.00, 70.00) Node 716: (2.00, 60.00) Node 717: (2.00, 61.00) Node 718: (2.00, 62.00) Node 719: (2.00, 63.00) Node 720: (2.00, 64.00) Node 721: (2.00, 65.00) Node 722: (2.00, 66.00) Node 723: (2.00, 67.00) Node 724: (2.00, 68.00) Node 725: (2.00, 69.00) Node 726: (2.00, 70.00) Node 727: (3.00, 60.00) Node 728: (3.00, 61.00) Node 729: (3.00, 62.00) Node 730: (3.00, 63.00) Node 731: (3.00, 64.00) Node 732: (3.00, 65.00) Node 733: (3.00, 66.00) Node 734: (3.00, 67.00) Node 735: (3.00, 68.00) Node 736: (3.00, 69.00) Node 737: (3.00, 70.00) Node 738: (4.00, 60.00) Node 739: (4.00, 61.00) Node 740: (4.00, 62.00) Node 741: (4.00, 63.00) Node 742: (4.00, 64.00) Node 743: (4.00, 65.00) Node 744: (4.00, 66.00) Node 745: (4.00, 67.00) Node 746: (4.00, 68.00) Node 747: (4.00, 69.00) Node 748: (4.00, 70.00) Node 749: (5.00, 60.00) Node 750: (5.00, 61.00) Node 751: (5.00, 62.00) Node 752: (5.00, 63.00) Node 753: (5.00, 64.00) Node 754: (5.00, 65.00) Node 755: (5.00, 66.00) Node 756: (5.00, 67.00) Node 757: (5.00, 68.00) Node 758: (5.00, 69.00) Node 759: (5.00, 70.00) Node 760: (6.00, 60.00) Node 761: (6.00, 61.00) Node 762: (6.00, 62.00) Node 763: (6.00, 63.00) Node 764: (6.00, 64.00) Node 765: (6.00, 65.00) Node 766: (6.00, 66.00) Node 767: (6.00, 67.00) Node 768: (6.00, 68.00) Node 769: (6.00, 69.00) Node 770: (6.00, 70.00) Node 771: (7.00, 60.00) Node 772: (7.00, 61.00) Node 773: (7.00, 62.00) Node 774: (7.00, 63.00) Node 775: (7.00, 64.00) Node 776: (7.00, 65.00) Node 777: (7.00, 66.00) Node 778: (7.00, 67.00) Node 779: (7.00, 68.00) Node 780: (7.00, 69.00) Node 781: (7.00, 70.00) Node 782: (8.00, 60.00) Node 783: (8.00, 61.00) Node 784: (8.00, 62.00) Node 785: (8.00, 63.00) Node 786: (8.00, 64.00) Node 787: (8.00, 65.00) Node 788: (8.00, 66.00) Node 789: (8.00, 67.00) Node 790: (8.00, 68.00) Node 791: (8.00, 69.00) Node 792: (8.00, 70.00) Node 793: (4.33, 67.50) Node 794: (4.33, 68.50) Node 795: (4.33, 69.50) Node 796: (4.33, 70.50) Node 797: (4.33, 71.50) Node 798: (4.33, 72.50) Node 799: (4.33, 73.50) Node 800: (4.33, 74.50) Node 801: (4.33, 75.50) Node 802: (4.33, 76.50) Node 803: (4.33, 77.50) Node 804: (5.33, 67.50) Node 805: (5.33, 68.50) Node 806: (5.33, 69.50) Node 807: (5.33, 70.50) Node 808: (5.33, 71.50) Node 809: (5.33, 72.50) Node 810: (5.33, 73.50) Node 811: (5.33, 74.50) Node 812: (5.33, 75.50) Node 813: (5.33, 76.50) Node 814: (5.33, 77.50) Node 815: (6.33, 67.50) Node 816: (6.33, 68.50) Node 817: (6.33, 69.50) Node 818: (6.33, 70.50) Node 819: (6.33, 71.50) Node 820: (6.33, 72.50) Node 821: (6.33, 73.50) Node 822: (6.33, 74.50) Node 823: (6.33, 75.50) Node 824: (6.33, 76.50) Node 825: (6.33, 77.50) Node 826: (7.33, 67.50) Node 827: (7.33, 68.50) Node 828: (7.33, 69.50) Node 829: (7.33, 70.50) Node 830: (7.33, 71.50) Node 831: (7.33, 72.50) Node 832: (7.33, 73.50) Node 833: (7.33, 74.50) Node 834: (7.33, 75.50) Node 835: (7.33, 76.50) Node 836: (7.33, 77.50) Node 837: (8.33, 67.50) Node 838: (8.33, 68.50) Node 839: (8.33, 69.50) Node 840: (8.33, 70.50) Node 841: (8.33, 71.50) Node 842: (8.33, 72.50) Node 843: (8.33, 73.50) Node 844: (8.33, 74.50) Node 845: (8.33, 75.50) Node 846: (8.33, 76.50) Node 847: (8.33, 77.50) Node 848: (9.33, 67.50) Node 849: (9.33, 68.50) Node 850: (9.33, 69.50) Node 851: (9.33, 70.50) Node 852: (9.33, 71.50) Node 853: (9.33, 72.50) Node 854: (9.33, 73.50) Node 855: (9.33, 74.50) Node 856: (9.33, 75.50) Node 857: (9.33, 76.50) Node 858: (9.33, 77.50) Node 859: (10.33, 67.50) Node 860: (10.33, 68.50) Node 861: (10.33, 69.50) Node 862: (10.33, 70.50) Node 863: (10.33, 71.50) Node 864: (10.33, 72.50) Node 865: (10.33, 73.50) Node 866: (10.33, 74.50) Node 867: (10.33, 75.50) Node 868: (10.33, 76.50) Node 869: (10.33, 77.50) Node 870: (11.33, 67.50) Node 871: (11.33, 68.50) Node 872: (11.33, 69.50) Node 873: (11.33, 70.50) Node 874: (11.33, 71.50) Node 875: (11.33, 72.50) Node 876: (11.33, 73.50) Node 877: (11.33, 74.50) Node 878: (11.33, 75.50) Node 879: (11.33, 76.50) Node 880: (11.33, 77.50) Node 881: (12.33, 67.50) Node 882: (12.33, 68.50) Node 883: (12.33, 69.50) Node 884: (12.33, 70.50) Node 885: (12.33, 71.50) Node 886: (12.33, 72.50) Node 887: (12.33, 73.50) Node 888: (12.33, 74.50) Node 889: (12.33, 75.50) Node 890: (12.33, 76.50) Node 891: (12.33, 77.50) Node 892: (0.00, 75.00) Node 893: (0.00, 76.00) Node 894: (0.00, 77.00) Node 895: (0.00, 78.00) Node 896: (0.00, 79.00) Node 897: (0.00, 80.00) Node 898: (0.00, 81.00) Node 899: (0.00, 82.00) Node 900: (0.00, 83.00) Node 901: (0.00, 84.00) Node 902: (0.00, 85.00) Node 903: (1.00, 75.00) Node 904: (1.00, 76.00) Node 905: (1.00, 77.00) Node 906: (1.00, 78.00) Node 907: (1.00, 79.00) Node 908: (1.00, 80.00) Node 909: (1.00, 81.00) Node 910: (1.00, 82.00) Node 911: (1.00, 83.00) Node 912: (1.00, 84.00) Node 913: (1.00, 85.00) Node 914: (2.00, 75.00) Node 915: (2.00, 76.00) Node 916: (2.00, 77.00) Node 917: (2.00, 78.00) Node 918: (2.00, 79.00) Node 919: (2.00, 80.00) Node 920: (2.00, 81.00) Node 921: (2.00, 82.00) Node 922: (2.00, 83.00) Node 923: (2.00, 84.00) Node 924: (2.00, 85.00) Node 925: (3.00, 75.00) Node 926: (3.00, 76.00) Node 927: (3.00, 77.00) Node 928: (3.00, 78.00) Node 929: (3.00, 79.00) Node 930: (3.00, 80.00) Node 931: (3.00, 81.00) Node 932: (3.00, 82.00) Node 933: (3.00, 83.00) Node 934: (3.00, 84.00) Node 935: (3.00, 85.00) Node 936: (4.00, 75.00) Node 937: (4.00, 76.00) Node 938: (4.00, 77.00) Node 939: (4.00, 78.00) Node 940: (4.00, 79.00) Node 941: (4.00, 80.00) Node 942: (4.00, 81.00) Node 943: (4.00, 82.00) Node 944: (4.00, 83.00) Node 945: (4.00, 84.00) Node 946: (4.00, 85.00) Node 947: (5.00, 75.00) Node 948: (5.00, 76.00) Node 949: (5.00, 77.00) Node 950: (5.00, 78.00) Node 951: (5.00, 79.00) Node 952: (5.00, 80.00) Node 953: (5.00, 81.00) Node 954: (5.00, 82.00) Node 955: (5.00, 83.00) Node 956: (5.00, 84.00) Node 957: (5.00, 85.00) Node 958: (6.00, 75.00) Node 959: (6.00, 76.00) Node 960: (6.00, 77.00) Node 961: (6.00, 78.00) Node 962: (6.00, 79.00) Node 963: (6.00, 80.00) Node 964: (6.00, 81.00) Node 965: (6.00, 82.00) Node 966: (6.00, 83.00) Node 967: (6.00, 84.00) Node 968: (6.00, 85.00) Node 969: (7.00, 75.00) Node 970: (7.00, 76.00) Node 971: (7.00, 77.00) Node 972: (7.00, 78.00) Node 973: (7.00, 79.00) Node 974: (7.00, 80.00) Node 975: (7.00, 81.00) Node 976: (7.00, 82.00) Node 977: (7.00, 83.00) Node 978: (7.00, 84.00) Node 979: (7.00, 85.00) Node 980: (8.00, 75.00) Node 981: (8.00, 76.00) Node 982: (8.00, 77.00) Node 983: (8.00, 78.00) Node 984: (8.00, 79.00) Node 985: (8.00, 80.00) Node 986: (8.00, 81.00) Node 987: (8.00, 82.00) Node 988: (8.00, 83.00) Node 989: (8.00, 84.00) Node 990: (8.00, 85.00)
For more details on the ’meshgrid’, kindly go through the following documentation

Weitere Antworten (2)

Bruno Luong
Bruno Luong am 28 Jun. 2023
Code from this thread. Not sure why you must use meshgrid
m = 7;
n = 8;
[A,B,C,X,Y] = HexGraphPart2(m,n);
G = graph(A+B+C);
close all
figure;
h = plot(G);
% Change node coordinates on regular hexagonal pattern
set(h,'XData',X(:),'YData',Y(:));
axis('equal');
function [H,NW,NE,X,Y]=HexGraphPart2(m,n)
x = (0:m-1)';
y = (0:n-1);
K = 1 + x + m*y;
p = m*n;
H = sparse(K(1:2:end-1,1:2:end),K(2:2:end,1:2:end),1,p,p) + ...
sparse(K(2:2:end-1,2:2:end),K(3:2:end,2:2:end),1,p,p);
NW = sparse(K(1:2:end,1:2:end-1),K(1:2:end,2:2:end),1,p,p) + ...
sparse(K(2:2:end,2:2:end-1),K(2:2:end,3:2:end),1,p,p);
NE = sparse(K(2:2:end,1:2:end-1),K(2:2:end,2:2:end),1,p,p) + ...
sparse(K(1:2:end,2:2:end-1),K(1:2:end,3:2:end),1,p,p);
H = H+H';
NW = NW+NW';
NE = NE+NE';
if nargout >= 5
X = (3*x - mod(x+y,2))/2;
Y = (sqrt(3)/2)*y + 0*x;
end
end
  1 Kommentar
Nupur
Nupur am 28 Jun. 2023
Thanks, we can even think this approach if meshgrid usage wasnt mandatory

Melden Sie sich an, um zu kommentieren.


Bruno Luong
Bruno Luong am 28 Jun. 2023
Bearbeitet: Bruno Luong am 28 Jun. 2023
If you need coordinates and no connectivity graph, the code can be simplified, you can use meshgrid if you wish to MATLAB autoexpansion is much prefered
m = 7;
n = 8;
x = (0:m-1)';
y = (0:n-1);
X = (3*x - mod(x+y,2))/2;
Y = (sqrt(3)/2)*y + 0*x;
close all
figure;
h = plot(X,Y,'ok');
axis('equal');
  2 Kommentare
Nupur
Nupur am 28 Jun. 2023
We will require connectivity table,graph is just for interpretation
Bruno Luong
Bruno Luong am 28 Jun. 2023
Bearbeitet: Bruno Luong am 28 Jun. 2023
If you absolutely want to use meshgrid then
m = 7;
n = 8;
[x,y] = meshgrid(0:m-1, 0:n-1);
X = (3*x - mod(x+y,2)) / 2;
Y = (sqrt(3)/2)*y;
figure;
h = plot(X,Y,'ok');
axis('equal');

Melden Sie sich an, um zu kommentieren.

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by