allotment of points in meshgrid

6 visualizaciones (últimos 30 días)
Arundhatee Talukdar
Arundhatee Talukdar el 24 de Nov. de 2011
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?

Respuestas (1)

Walter Roberson
Walter Roberson el 24 de Nov. de 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.]
  1 comentario
Arundhatee Talukdar
Arundhatee Talukdar el 24 de Nov. de 2011
Hey Walter, thank you so much for the answer, it is really really helpful for me to understand meshgrid better! However, I am not sure how to use imshow for my need.
I draw a figure (to be precise, a one line diagram of a power system) by developing matlab code. And I have certain values of a particular property (say Vi) in certain points of that figure, to be precise i=no of bus. I have 30 buses. I use meshgrid to create coordinate at all point of the plot.
Now I need to calculate a value (say Vp) for all the points in the plot using the abovementioned value at the given points, I am using the following formula
Vp=∑ (Vi/dpi2 )/∑( 1/dpi2 )
Where d = distance between point p and i
I am getting the values, but somehow some mistake in accessing the point, when I am trying to reverse YDir, the one line diagram is also getting reversed. Here is my code...
for i=1:30
busc (i,1)=xyb((2*i-1),1)+(xyb(2*i,1)-xyb((2*i-1),1))/2;% x coordinate for bus center ie gives me the coordinates of the point where V is given
busc (i,2)=xyb(2*i,2); % y coordinate
end
for i=1:180 % to access meshgrid points
for j=1:180 % to access meshgrid points
for k=1:30 % to access all the buses
dist(k)=1/(((busc(k, 1) - i)^2+ (busc(k, 2) - j)^2)^0.5)^2; %for calculating the fv value
vvolt(k)=r.bus(k,8)./(((busc(k, 1) - i)^2+ (busc(k, 2) - j)^2)^0.5)^2;%for calculating the fv value
end
rr=sum(vvolt')'; %for calculating the fv value
uu=sum(dist')'; %for calculating the fv value
result=rr./uu;
fvolt(i,j)=result;
end
end
g= pcolor(X,Y,fvolt);
set(g,'LineStyle','none')
myColorMap = flipud(jet);
colormap(myColorMap);
colorbar;
set(gca,'YDir','reverse');
axis off;
WHERE is my mistake!

Iniciar sesión para comentar.

Categorías

Más información sobre Surface and Mesh Plots en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by