I have a 3d matrix with scattered points (Nx4 matrix, x-y-z-data). My aim is to link the closest points together and register each chain in an Kx4 array (x, y, z, data), K being the chain length. The total number of chains depends on the points... A particularity is that these lines only go upwards (z+), I don't want to link points on same z, or go down.
I have been trying different strategies so far, one being with another array shape (Mx4xNz - basically meaning the values were stacked per z's instead of being all on a 2d matrix):
1. pick a point at level Zn
2. go to level Zn+1, look for the closest point in a range of coordinates x,y using delaunayTriangulation and nearestNeighbor
3. register the point into a vector
(I suspect there are other possibilities using nearestNeighbor with the Nx4 matrix, but i can't think how to 'direct' the search upwards and chain the successive points... )
I find myself with the following problem : The finding of nearest point upwards seems to work well but in 1 horizontal direction only!!
Anyone has an idea as to why this is happens? I suspect the problem might be with assigning correctly the nearest neighbor found, but I don't see how the extraction I did in my code below would be wrong?? Thanks for any help!!
Note - During the loop I have the warning : Duplicate data points have been detected and removed. The Triangulation indices are defined with respect to the unique set of points in delaunayTriangulation property X.
for i = 1:s;
Point_n = Wn(pp_id,:);