How to show the distance between two points?

1 view (last 30 days)
I have a matrix containing x-y-coordinates of two points. The points are centers of circles I found in my image. 1st & 2nd columns represent the first piont, whereas 3rd & 4th columns represent the other one:
points =
427.4762 968.9869 436.1298 939.4800
410.3451 531.7527 415.7316 504.8123
289.3263 833.7752 315.2286 847.8880
32.8322 467.8996 15.9475 456.3964
184.0949 927.8066 187.6726 898.4243
167.1554 801.0665 161.9174 801.4695
70.6457 803.9617 50.3906 793.8978
187.0649 600.8996 190.2172 559.2566
100.6608 741.2848 113.0292 723.1275
107.4194 407.3231 110.2720 349.0485
145.1516 342.2777 139.1603 349.0192
207.9099 505.1574 210.9875 474.2046
35.5727 686.9287 25.5995 677.6045
66.5224 412.8655 60.7199 370.5793
56.2066 637.5961 44.8846 634.1563
199.3653 466.6608 193.0445 465.6853
218.6190 452.8426 210.9875 474.2046
81.8380 569.2056 81.4730 564.7555
218.9364 124.3950 213.2326 75.4309
105.9599 779.3439 114.1407 780.7945
53.9224 524.8930 65.8658 510.9172
73.6517 658.9759 57.3831 664.3180
19.9922 548.0229 12.7127 541.9428
231.3526 810.2561 230.0475 834.9254
68.1422 556.0996 60.2532 567.7775
9.4267 564.2696 12.7127 541.9428
10.4302 649.0322 25.3083 632.5705
13.6125 858.7830 40.8027 860.6428
50.4056 800.7158 50.3906 793.8978
187.6887 654.8640 159.9689 623.4049
29.0610 484.5180 57.1913 478.6240
41.7510 919.2462 65.8827 900.7444
109.4590 842.2688 114.1407 780.7945
21.4602 223.1551 20.3139 173.5782
50.5669 770.8235 50.3906 793.8978
54.4706 598.9854 52.4174 593.4113
27.5837 323.1575 41.3871 355.3593
Now I'd like to show the distances between the two points of a row in my image. Is it possible to draw a line or an arrow ?

Answers (4)

Matt J
Matt J on 12 Nov 2012
distances=sqrt( sum( (points(1:2)-points(3:4)).^2 ,2 ) );

Matt J
Matt J on 12 Nov 2012
Use the QUIVER command
  2 Comments
Alexander Esser
Alexander Esser on 12 Nov 2012
the command shows me an arrow on a seperate plot. i want to show ON my image. how?
Matt J
Matt J on 12 Nov 2012
Use the HOLD command to freeze the image and then superimpose the quiver plot on top of it.

Sign in to comment.


Azzi Abdelmalek
Azzi Abdelmalek on 12 Nov 2012
Edited: Azzi Abdelmalek on 12 Nov 2012
n=size(points,1)
x=points(:,[1 3]);
y=points(:,[2 4]);
hold on;arrayfun(@(t) plot(x(t,:),y(t,:)),1:n)

Chien Duong
Chien Duong on 7 Apr 2017
Edited: Chien Duong on 7 Apr 2017
The plot function work like this x= [1,2]; y=[3,5]. Matlab will plot the point 1,3 with 2,5. So in order to draw the line between two point You can try this:
x = [3,5];
y = [7,2];
c=x;
x(1,2)=y(1,1);
y(1,1)=c(1,2);
plot(x,y)

Categories

Find more on Vector Fields 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!