I tried to create a function in MATLAB, which returns a vector of the distances between neighboring points in a list of points (x1,y1),...,(xn,yn)
.
That is ["distance (x1,y1) to (x2,y2)", ... ,"distance (xn-1,yn-1) to (xn,yn)","distance (xn,yn) to (x1,y1)"]
.
To do this, my idea was to work with two vectors:
The original one [(x1,y1),...,(xn,yn)]
and [(xn,yn),(x1,y1),...,(xn-1,yn-1)]
.
Now I built this function:
function erg = distVec(xy1)
n = length(xy1);
xy2 = cat(1,xy1(2:end,:),xy1(1,:));
% define snd vector
erg = [];
for j=n
erg = cat(2,erg,norm((xy1(j,:)-xy2(j,:))));
% norm(...) equals distance between two neighboring points
end
end
But instead of an vector with the distances, this function returns only the last distance evaluated.
What is wrong?
Thanks!
xy1
supposed to have? - jub0bs