数学建模之灰色理论+马氏距离

x1= xlsread('schoolMatchData.xlsx','H2:M3002');
x=x1+abs(min(min(x1))); %%% positive all the data by add the abs of the minimum

yangben=x; %样本数据

fangzhen=x; %待判数据


[rows,cols]=size(fangzhen);
p=0.5;    %分辨系数
[m,n]=size(yangben);      
R1=[];


for irow=1:rows
     yy=fangzhen(irow,:);
     cc=yangben;
     cc(irow,:)=[];
     data_gyh=[yy;cc];


     for i=2:m
         for j=1:n
             Dij(i-1,j)=abs(data_gyh(1,j)-data_gyh(i,j)); %%%minus reference and abs
         end
     end



     Dijmax=max(max(Dij));  %%%两级差
     Dijmin=min(min(Dij));


     for i=1:m-1  %%%点关联系数
         for j=1:n
             Lij(i,j)=(Dijmin+p*Dijmax)/(Dij(i,j)+p*Dijmax);
         end
     end

     LijRowSum=sum(Lij');

     for i=1:m-1   %%%关联度
         Rij(i)=LijRowSum(i)/n;
     end
     R1=[R1;Rij];
end

%%%关联度矩阵
R=zeros(430,430);
for ww=1:430
R(ww,1:ww-1)=R1(ww,1:ww-1);
R(ww,ww)=1;
R(ww,ww+1:end)=R1(ww,ww:end);
End

马氏距离:

 X = xlsread('NewSchoolMatchData.xlsx','A1:F3001');
Y = pdist(X,'mahal');

你可能感兴趣的:(数学建模)