Home > Blockchain >  How can I remove the 'fishbowl' effect when creating a square grid on MATLAB?
How can I remove the 'fishbowl' effect when creating a square grid on MATLAB?

Time:11-11

I have been trying to create a graph representing a square grid with 8 nodes. I have been using code given by Mathworks enter image description here

But I just wondered if I could make the image less curved. In order to make the graph look more 'uniform' and have all the edges the same length.

CodePudding user response:

The graph G contains no coordinates for the nodes, so MATLAB basically has to "guess" where to put them (and does a remarkably good job). You can use the additional argument XData, YData (and ZData) to add coordinates to your nodes (see documentation), so in your case you might want to use e.g meshgrid:

n = 8; 
A = delsq(numgrid('S',n 2)); 
G = graph(A,'omitselfloops'); 
[x,y] = meshgrid(1:n, 1:n);
p = plot(G, 'XData',x(:), 'YData',y(:));
  • Related