calculate distance between XY pair
Ältere Kommentare anzeigen
Hi
I want to calculate distance between XY points but as pair not all of them.
I used 'pdist' and 'pdist2' function but they calculate distance for all points.
I want to calculate point 1(xy) with point 2(xy) then point 2(xy) with point 3(xy) and go on (it is a part of recorded movments).
I think I will need to write a loop but I am not sure about proper function.
3 Kommentare
infinity
am 26 Jun. 2019
Hello,
Let me make sure that I understant you well.
You have data like A = [ 1 3; 2 4; 3 6] where the first column of A is x and the second column of A is y. You want to compute distance between (1, 3) and (2,4) then (2,4) and (3,6). Is it correct?
Boby S
am 27 Jun. 2019
infinity
am 27 Jun. 2019
Hello,
So, I think the anwser below is what you want.
Akzeptierte Antwort
Weitere Antworten (1)
Pawan Sharma
am 30 Jul. 2020
You can use the method suggested by Walter in a forloop to get the required ansewer
A = [ 1 3; 2 4; 3 6]
distanceList = zeros(1,size(A,1)-1); % calculated distance will be stored here
for i = 1:size(A,1)-1
data1 = A(i,:);
data2 = A(i+1,:)
distance = sqrt(((data1(1)-data2(1))^2)+(data1(2)-data2(2))^2);
distanceList(i) = distance;
end
Kategorien
Mehr zu Creating and Concatenating Matrices finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!