Hello I have a feature vector of 13 dimensions for m samples.I am trying to find the nearest neighbor of the each sample.
[m,~] = size(featurevector);X = [];Y = [];for i = 1: m-1 if (featurevector(i,14) == 3) X = [X;featurevector(i,1:13)]; Y = [Y;featurevector(i,1:13)]; endend
I can get the distances values matrix which gives the distances of all the points when using
d = pdist2(X,Y,'euclidean');
but i want the indexs which 3 neighbors are near to each data point so i tried
[idx,dist] = knnsearch(X,Y,'k',3,'distance','euclidean');
but it shows an error
Error using pdist2 Too many input arguments. Error in ExhaustiveSearcher/knnsearch (line 207) [dist,idx] = pdist2(obj.X,Y, distMetric, arg{:}, 'smallest',numNN); Error in knnsearch (line 144) [idx, dist] = knnsearch(O,Y,'k',numNN, 'includeties',includeTies);
I expect the result to be an array showing the nearest neighbor for each point in the featurevector. Can any one suggest where I went wrong ?
Best Answer