Hello, 
    I'm trying to compare an image of a path to the points in the generated via matlab. I have an image of the path, turinging it into a binary image, skeltonizing the image and taking the row and column data for the skelton. I want to have points of the line in order to follow down the line. I found this code to do so but for some reason its adding some some extra line to the end. I do not know why.
The code I used for sorting is as follows 
Coordinates=[col row]; 
dist = pdist2(Coordinates,Coordinates); 
N = size(Coordinates,1); 
result = NaN(1,N); 
result(1) = 1; 
for ii=2:N  
    dist(:,result(ii-1)) = Inf;
    [~, closest_idx] = min(dist(result(ii-1),:));
    result(ii) = closest_idx;
end
Coordinates=Coordinates(result,:); 
Thank you