PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, June 28, 2022

[FIXED] How can I remove the 'fishbowl' effect when creating a square grid on MATLAB?

 June 28, 2022     graph, graph-theory, grid, matlab     No comments   

Issue

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

n = 8;
A = delsq(numgrid('S',n+2));
G = graph(A,'omitselfloops');
p = plot(G);` 

The plotted result is:

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.


Solution

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(:));


Answered By - flawr
Answer Checked By - Marilyn (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing