Most of the kdtree code for matlab has been implemented via mex files. I decided to come up with a purely matlab based implementation and so here it is .... The code is obviously expected to be slower than some of the c/c++ implementations that are out there but the fact that its implemented in matlab might make it useful in certain circumstances. Matlab doesnot have pointers and so i mimicked the pointer functionality by using a global cell array. I will appreciate any feedback on my submission ........
There seem to be some issues with the closestpointgood function. The following code shows that the distance according to this function is 0.0662 which is twice as much as the coordinates of another node: 0.0386.
X = 0.1321;
Y = 0.9393;
[index_vals,vector_vals,final_node] = kd_closestpointgood(tree,[X Y]);
thank you for all kd codes. So, i have one question. I want use kd_knn for each 3D point of matrix (X). I built kd tree for matrix (X) and i want to find knn for each point of this matrix. In kd_knn code i can use only one point. Thank you for you help and suggestions.
I have some bugs while using the function kd_nclosestpoints. It throws errors about the number of elements that the members of the kdtree struct have. i.e.:
??? Error using ==> gt
Too many input arguments.
Error in ==> kd_nclosestpoints at 21
if(n>tree.numpoints)
hi..actually i need matlab code for the design of IIR filter low pass filter i.e magnitude and group delay using genetic algorithm in matlab...reply me on my email address gurleensohi@yahoo.com
There is a bug in file kd_closestpointgood.m on lines 111 and 112
They are:
if (~isempty(tree_cell_2(node_number).left)) kd_closestpointgood(0,point,tree_cell_2(node_number).right);
Line 111 should instead check right not left:
if (~isempty(tree_cell_2(node_number).right))
Works great.
As you say the other implementations out there makes use of mex files. This being pure m files and with w ell commentated code makes it easy to modify for altered use. I added a stored functionvalue at every node. Works great so far!