资 源 简 介
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