MATLAB Answers

Pramod Bhat

k-NN search. What is the difference between these 2-codes ?

Asked by Pramod Bhat
on 15 Feb 2012
The program for k-NN search in MATLAB. 
load fisheriris %inbuilt data set provided in MATLAB. 
x = meas(:,3:4);
newpoint = [5 1.45];
[n,d] = knnsearch(x,newpoint,'k',10)  %my doubt is here. 
line(x(n,1),x(n,2),'color',[.5 .5 .5],'marker','o',...
%modified program for my requirement with different data set. x and z are the two variables with 24 elements in each. 
load stroke
line(newpoint(1),newpoint(2),'marker','x','co  lor','k',...
 [n,d] = knnsearch(x,newpoint,'k',10) % when i run , it gives error here. what is the difference between the original code and modified code ? infact 'newpoint' in the original program is a vector.  
line(x(n,1),x(n,2),'color',[.5 .5 .5],'marker','o',...



No products are associated with this question.

1 Answer

Answer by Tom Lane
on 15 Feb 2012
 Accepted answer

You have supplied only x, not [x z], as the first argument to knnsearch. Your newpoint vector, on the other hand, has two columns.


Pramod Bhat
on 16 Feb 2012

Hai. I have sent you an email. Please help me out in this regard.

How to predict data using KNN ?

I have a vector of 80 years of data. I want to predict for 30 years. Please let me know how it is possible to using KNN?

Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi test

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!