how to find distance between two points?

1.150 Ansichten (letzte 30 Tage)
bsd
bsd am 27 Sep. 2011
Beantwortet: Daksh am 2 Feb. 2023
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

Akzeptierte Antwort

Lucas García
Lucas García am 27 Sep. 2011
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
  3 Kommentare
Mohd Aaqib Lone
Mohd Aaqib Lone am 5 Nov. 2019
I want to measure distance between one point to other more than ten points, what i mean is like i have ten markers on one line and i want to compute distance from the ist marker with other 9 markers. How can I do it in MATLAB. Please answer.
zoher badr
zoher badr am 14 Feb. 2021
in this case you have to have a nested loop so you gaurantee to reach each point int the list

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (6)

MathWorks Support Team
MathWorks Support Team am 8 Nov. 2018
The distance between two points x and y is the same as the magnitude of the vector that points from one point to the other:
>> x = [0 0];
>> y = [2 1];
>> norm(x-y)
ans =
2.2361
  2 Kommentare
Peize Li
Peize Li am 30 Dez. 2020
Will i get a column vector of distances if I try norm(x-y), where x and y are two 3 x 2 vectors?
Advik Solanki
Advik Solanki am 28 Feb. 2022
thanks

Melden Sie sich an, um zu kommentieren.


Walter Roberson
Walter Roberson am 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

Fangjun Jiang
Fangjun Jiang am 27 Sep. 2011
Pos=[x1 x2;y1 y2]
D=dist(Pos);
  4 Kommentare
Fangjun Jiang
Fangjun Jiang am 27 Sep. 2011
Sorry, Walter. You are right, the dist() function is from the Neural Network Toolbox.
Fangjun Jiang
Fangjun Jiang am 27 Sep. 2011
I am using my new MATLAB version today. It has a bunch of toolbox. Nice!

Melden Sie sich an, um zu kommentieren.


Twinkle Jain
Twinkle Jain am 17 Mär. 2017
X = [0,0;2,1];
d = pdist(X,'euclidean')

Sohrab Dorodvand
Sohrab Dorodvand am 2 Aug. 2018
if i was to compare one point of a 1d graph and to compare the distances between that point(the reference point) to others on the graph. how can i do that?

Daksh
Daksh am 2 Feb. 2023
I understand you're experiencing doubts over calculating distance between 2 points in the figure for which you have variable values saved in workspace. You can use one of the following methods for your utility:
  1. norm(): distance between two points as the norm of the difference between the vector elements
  2. pdist(X): Euclidean distance between pairs of observations in X
  3. pdist2(X,Y,Distance): distance between each pair of observations in X and Y using the metric specified by Distance.
  4. distance(): distance between two points in Geographic space
Hope this helps!

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by