# Demo entry 6714153

qqq

Submitted by anonymous on Feb 12, 2018 at 03:38
Language: Matlab. Code size: 1.8 kB.

```%m cities, n evaluation indicators
m=9;
n=14;
X=ones(m,n);

X=xlsread('2015data.xlsx');
%Normalize temperature and precipitation data
tem_rain=zeros(9,2);
for i=1:9
for j=1:2
tem_rain(i,j)=X(i,j);
end
end
max_tem_rain=max(tem_rain);
min_tem_rain=min(tem_rain);

for i=1:9
for j=1:2
X(i,j)=abs(X(i,j));
X(i,j)=(X(i,j)-min_tem_rain(j))/(max_tem_rain(j)-min_tem_rain(j))*10;
if X(i,j)==0
X(i,j)=1;
end
end
end

biaozhun_X=X;

%The original indicator data is standardized
biaozhi_zhengxiang=ones(1,n);%biaozhi_zhengxiang 1 if positive
min_hang=min(X,[],2);
max_hang=max(X,[],2);
for i=1:m
for j=1:n
if biaozhi_zhengxiang(1,j)==1
X(i,j)=(X(i,j)-min_hang(i))/(max_hang(i)-min_hang(i));
end

if biaozhi_zhengxiang(1,j)==0
X(i,j)=(max_hang(i)-X(i,j))/(max_hang(i)-min_hang(i));
end
end
end

%After processing, calculate the proportion of the i th city index value
%under the jth index P (i, j)
P=ones(m,n);
hang_sum=sum(X,1);
for i=1:m
for j=1:n
P(i,j)=X(i,j)/hang_sum(j);
end
end

%Calculate the entropy of the jth index Ej:
E=ones(1,n);
lnP=log(P);
hePlnP=zeros(1,n);

for i=1:m
for j=1:n
if lnP(i,j)==-Inf
lnP(i,j)=0;
end
hePlnP(1,j)=hePlnP(1,j)+P(i,j)*lnP(i,j);
end
end

for i=1:n
E(1,i)=-(1/log(m))*hePlnP(1,i);
end

%Calculate the difference coefficient of evaluation index j gj:
g=ones(1,n);
for j=1:n
g(1,j)=1-E(1,j);
end

%3)Calculate the weight of evaluation index j wj:
w=ones(1,n);
for j=1:n
w(1,j)=g(1,j)/sum(g);
end
w

%fid = fopen('2015data_ans.txt','wt');
%fprintf(fid,'%g\t',w);
%fclose(fid);
```

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.