How can i measure the distance between points in a scatter graph

4 Ansichten (letzte 30 Tage)
callum connacher
callum connacher am 10 Feb. 2017
Kommentiert: José-Luis am 10 Feb. 2017
Looking to measure the Manhattan distance between the points on my scatter graph

Antworten (1)

José-Luis
José-Luis am 10 Feb. 2017
pdist() with the 'cityblock' argument should do the trick.
  2 Kommentare
callum connacher
callum connacher am 10 Feb. 2017
I cant seem to get it to work. What I have is a group of 8 points and want to gather a distance matrix for the manhattan distance between them, below is the script i am trying to use, any help?
x = [0, 6, 6, 6, 7, 7, 8, 8];
y = [0, 0, 2, -2, 2, -2, 2, -2];
A= plot(x,y,'bo')
axis([-2,10,-5,5])
labels={'exit','terminal','Gate1','Gate2','Gate3', 'Gate4','Gate 5','Gate6',};
text (x-0.5,y-1,labels,'bottom')
title(' Airport Layout')
D = pdist(A,'cityblock')
José-Luis
José-Luis am 10 Feb. 2017
You are trying to get the distance of a graphic object handle (in your case a line).
Perhaps this is what you meant:
x = [0, 6, 6, 6, 7, 7, 8, 8];
y = [0, 0, 2, -2, 2, -2, 2, -2];
D = pdist([x',y'],'cityblock')
Please read the documentation. Also, please accept the answer that best solves your problem.

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by