allotment of points in meshgrid
7 views (last 30 days)
Show older comments
When I use a meshgrid [X, Y]=meshgrid(1:180,1:180) how the points are devided in the plot? I mean to ask the very first point in the origin is (0,0) or (180,180). The main question is the numbering of the points starts from top of the plot or bottom of the plot?
0 Comments
Answers (1)
Walter Roberson
on 24 Nov 2011
meshgrid() does not create plots: it creates arrays. The arrays created are not necessarily in numerical order: they are in order according to the list of values that are given as arguments to meshgrid(). For example, meshgrid([9 2 5],-3:-1:-6) is valid.
When coordinates are used as (X,Y) coordinates for line plots or surface plots or patches, then the usual convention applies, that the origin is (0,0) in data coordinates, and that the first coordinate is treated as X (usually interpreted as horizontal distance increasing from left to right), and that the second coordinate is treated as Y (usually interpreted as vertical distance increasing from bottom to top).
However, when you create images by way of image() or imagesc() or imshow(), then by default those routines switch the coordinate system so that the first coordinate is still X increasing towards the right, but that the second coordinate as treated as Y increasing from top to bottom.
The actual mechanism for changing the coordinate system so that Y increases downwards, is to set the axes property 'YDir' to 'reverse'; when 'YDir' is 'normal' then the Y increaes from bottom to top. The command shortcut to set the YDir property is
axes xy
for normal bottom to top, and
axes ij
for "reversed" top to bottom.
There is no inherent numbering of points in a plot: there are only coordinate values.
If you were to create a 2D array and were to display it using surf(), and in that call you did not pass in an explicit list of X or Y coordinates, then the implicit ordering used would be that the rows would go up (bottom to top) and the columns would go would go across (left to right). This can be surprising at times but is usually what is wanted.
[I should double-check the default ordering for imag() before saying anything explicit here.]
See Also
Categories
Find more on Surface and Mesh Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!