MATLAB: Distance between two points – use ginput!

distanceginputmeasurepoints

Hi quys, please do you have any idea, how two measure distance between two points? I have my script (below) and a need measure distance between two points. Its mean – when I click (use ginput) six-times – i have six points and I need measure distance between – first+second , third+fourth and fifth+sixth. Its mean I have six points and 3 distances. I need keep my script, I just wanna edit it. Do you have please any idea how to edit it?? Thanks everybody for help!!!
MY SCRIPT:
close all
axis ([0 100 0 100]);
hold on
xy = [];
n = 0;
distance = [];
disp('SELECT POINTS LEFT BUTTON')
disp('RIGHT-CLICK SELECTED LAST POINT')
but = 1;
while but == 1
[xi,yi,but] = ginput(1);
plot(xi,yi,'ro')
n = n+1;
xy(:,n) = [xi;yi];
end

Best Answer

to find the distance between the two point use
d(1)= sqrt((x_point2-x_point1)^2+(y_point2-y_point1)^2);
d(2)= sqrt((x_point4-x_point3)^2+(y_point4-y_point3)^2);
d(3)= sqrt((x_point6-x_point5)^2+(y_point6-y_point5)^2);
you can generalize this and run it in a for loop
d(i)=sqrt((x_point(2*i)-x_point(2*i-1))^2+(y_point(2*i)-y_point(2*i-1))^2);
This is not the exact code but, you should be able to code it according to your requirements.
In you example
x_point1=xy(1,1)
y_point1=xy(2,1)
and so on..