Asked by bsd
on 27 Sep 2011

Hai,

I need to find the distance between two points in the figure, which I have plotted. Is there any function in matlab that could find the distance between two points. Looking for your reply.

BSD

*No products are associated with this question.*

Answer by Lucas García
on 27 Sep 2011

Accepted answer

You can use the pdist function in the Statistics Toolbox:

e.g: distance between points (0,0) and (2,1)

>> X = [0,0;2,1]; >> d = pdist(X,'euclidean') d =

2.2361

Answer by Walter Roberson
on 27 Sep 2011

No. You will have to code it yourself.

There are many different possible meanings for "distance". See http://en.wikipedia.org/wiki/Metric_%28mathematics%29#Examples

Answer by Fangjun Jiang
on 27 Sep 2011

Pos=[x1 x2;y1 y2] D=dist(Pos);

Show 1 older comment

Fangjun Jiang
on 27 Sep 2011

There are many call syntax of dist(). I though the OP wants the Euclidean distance between two points (x1,y1), (x2,y2), which should be sqrt((x1-x2)^2+(y1-y2)^2).

dist() can calculate the Euclidean distance of multiple points at once, it can certainly be used to calculate the distance for two points, although it seems to be an over-kill because the equation sqrt((x1-x2)^2+(y1-y2)^2) can do that too.

Since the OP asked for a MATLAB function, I thought this is the one.

pos=rand(2,5)

D=dist(pos)

Fangjun Jiang
on 27 Sep 2011

Sorry, Walter. You are right, the dist() function is from the Neural Network Toolbox.

Fangjun Jiang
on 27 Sep 2011

I am using my new MATLAB version today. It has a bunch of toolbox. Nice!

Opportunities for recent engineering grads.

## 0 Comments