I wanna use kNN algortihm without using kNNclassfy in matlab.But in my codes there is a big fault that i cant see now.Please contact with me immediately.Coz i have to finish it till tuesday.

figure axis([0,10,0,10])
[x,y] = ginput(20); scatter(x,y,'r+') A=[x,y];
hold
[z,t] =ginput(20); scatter(z,t,'b*')
B=[z,t];
[m,l]=ginput(10); scatter(m,l,'go') C=[m,l];
pause
k= input( ' k değerini giriniz= ')
%[row,col]=size(A);
%[row1,col1]=size(B);
%dist=zeros(row,row1);
%nnarray = zeros(row,row1);
%nnarray1 = zeros(row,m);
%for i=1:row
%for j=1:row1
% dist(i,j)=sqrt(sum((A(i,:)-C(j,:)).^2));
%end
%[y,index]=sort(dist(i,:));
%nnarray(i,:)=index';
% q=index';
%end
%for i=1:row
%for j=1:row1
% dist(i,j)=sqrt(sum((B(i,:)-C(j,:)).^2));
%end
%[y1,index1]=sort(dist(i,:));
% nnarray(i,:)=index1';
% w=index1';
%end
%pause(2)
%for i=1:10 %for j=1:k % q1(j,i)=q(j,i); % q1((j+1),k)=w(j,i) % end %end
%q2= sort(q1,1,'ascend');
%for f=1:10
%m=0
%n=0
%for i=1:k
%for j=1:10
% if q2(i,f) ==q(j,f)
% m=m+1
% else if q2(i,f) == w(j,f)
% n=n+1
% end
% end
% end
% end
%if m<n;
% e(f)=C(f)
% plot(e,'g+')
%else
% f(f)=C(f)
% plot (f,'r*')
%end
%end
In my question i want to create 2 clusters and classify the data via kNN.Especially each cluster(composed of 20 points) totally 40 point in figure frame via mouse we have to select the points with ginput code.Also for testing we have to select 10 points.We have to write down the kNN codes in matlab without using kNNclassify.Please show the cluster of the training data.

3 Comments

So, what is it doing wrong? You need to learn to use tools like the debugger. At the very least, learn to step through your code. Think about what it is doing, and why that is wrong. Otherwise, someone else needs to figure out what you are doing in this mess of code, half of which is left as comments. Of course, there are no true comments included that are of any value.
If you truly need a fast answer, you will find it far faster yourself, then you will get it by finding someone willing to make the significant investment of time to debug this mess.
All of the code after you ask the user to click points is commented out and I don't know what code you want in there or don't. And you haven't described what "a big fault" is, or where it occurs. After you read the helpful link John gave, I suggest you also read this link: http://blogs.mathworks.com/videos/2012/07/03/debugging-in-matlab/
in my code step by step i removed the comments .During running it is out of debugging.I still see any progress.So i asked it.

Sign in to comment.

Answers (0)

Asked:

on 25 Jan 2015

Commented:

on 26 Jan 2015

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!