%topsis
%矩阵x为
[n,m]=size(x);
%将把所有指标换成接近的大小?
%x(:,1)=x(:,1)*10;
zh=zeros(1,m);
d1=zeros(1,n); %最小值矩阵
d2=zeros(1,n);%最大值矩阵
c=zeros(1,n);%接近程度
%归一化
for i=1:m
for j=1:n
zh(i)=zh(i)+x(j,i)^2;
end
end
for i=1:m
for j=1:n
x(j,i)=x(j,i)/sqrt( zh(i));
end
end
%计算距离
xx=min(x);
dd=max(x);
for i=1:n
for j=1:m
d1(i)=d1(i)+(x(i,j)-xx(j))^2;
end
d1(i)=sqrt(d1(i));
end
for i=1:n
for j=1:m
d2(i)=d2(i)+(x(i,j)-dd(j))^2;
end
d2(i)=sqrt(d2(i));
end
%计算接近程度
for i=1:n
c(i)=d1(i)/(d2(i)+d1(i));
end
c
topsis--简单matlab代码
最新推荐文章于 2024-09-07 15:47:36 发布