accessing all points in a meshgrid plot

9 views (last 30 days)
Hello all,
I am trying to built an one line diagram of power system ie I have lines that depicts buses, transmission lines in my figure. Then I used meshgrid to divide my figure space into 100x100 points. (I guess now I have 10000 points in my figure). Now, I need to find out the distance of each of these 10000 points from the bus ie from the lines that depicts my buses. However, I am not able to access all the 10000 poins, only one fourth of the points are accessible.
[X,Y]= meshgrid(1:100, 1:100);
for ix=1:100
for iy=1:100
for i=1:30
dist(iy,i)=abs(xyb(2*i,1)- xyb((2*i-1),1)*(xyb((2*i-1),2)-Y(iy,1))-(xyb((2*i-1),1)-X(1,ix))*(xyb(2*i,2)-xyb((2*i-1),2)))/abs(xyb(2*i,1)-xyb((2*i-1),1));
end
end
end
Here
xyb= 30x2 matrice storing bus coordinate, I have 30 bus. Element 1,2 gives me the y coordinate of first bus, n 1 ,1 gives me the x coordinate.
Y= y coordinate for the particular point from where I need the distance to the buses. This is the meshgrid result.
I am trying to follow this formula for distance
=abs( (X2 -X1)(Y1- Y0 ) (X1 - X 0)(Y2-Y1))/ abs(X2 -X1)
For me y2 and y1 is same. an somebody please tell me, how to access all the points in the meshgrid plot!
  1 Comment
Sven
Sven on 10 Nov 2011
I don't entirely follow your question, but did you know you can calculate distances from every point in your grid to a given location, all in one line?
The short example below does just that (using euclidean distance rather than your formula), and shows the result as an image. Is this what you want to do for each of your bus points?
[X,Y]= meshgrid(1:100, 1:100);
myPt = [23.5 67.1];
distMat = sqrt((X-myPt(1)).^2 + (Y-myPt(2)).^2);
figure, imagesc(distMat), colorbar

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!