中文说明:clear;clc;ticload data.txt;a=data(1:30,1:4);aa=data(31:50,1:4);b=data(51:80,1:4);bb=data(81:100,1:4);c=data(101:130,1:4);cc=data(131:150,1:4);train_sample=cat(1,a,b,c);%组成训练样本(90*4)test_sample=cat(1,aa,bb,cc);%组成测试样本(60*4)k=5;cha=zeros(1,90);sum=0;[i,j]=size(train_sample);[u,v]=size(test_sample);for x=1:u for y=1:i result=sqrt((test_sample(x,1)-train_sample(y,1)).^2+(test_sample(x,2)-train_sample(y,2)).^2+(test_sample(x,3)-train_sample(y,3)).^2+(test_sample(x,4)-train_sample(y,4)).^2); cha(1,y)=result; end; [z,ind]=sort(cha); m1=0; m2=0; m3=0; for n=1:k if ind(1,n)<+30
English Description:
clear;clc;ticload data.txt;a=data(1:30,1:4);aa=data(31:50,1:4);b=data(51:80,1:4);bb=data(81:100,1:4);c=data(101:130,1:4);cc=data(131:150,1:4);Train_sample=cat (1,a,b,c);% composed of training samples (90*4)Test_sample=cat (1,AA,BB,CC);% test sample (60*4)k=5;cha=zeros(1,90);sum=0;[i,j]=size(train_sample);[u,v]=size(test_sample);for x=1:ufor y=1:iresult=sqrt((test_sample(x,1)-train_sample(y,1)).^2+(test_sample(x,2)-train_sample(y,2)).^2+(test_sample(x,3)-train_sample(y,3)).^2+(test_sample(x,4)-train_sample(y,4 )).^2);cha(1,y)=result;end;[z,ind]=sort(cha);m1=0;m2=0;m3=0;for n=1:kif ind(1,n)<+30m1=m1+1;elseif ind(1,n)>30&&ind(1,n)<+60m2=m2+1;elsem3=m3+1;endendL=[m1,m2,m3];if m1==max(L)m=1;elseif m2==max(L)<