You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
mycode/姚安欣/AHP.m

65 lines
1.1 KiB

%AHP步骤
clc,clear,close all;
A=[1,2,3,5
1/2,1,1/2,2
1/3,2,1,2
1/5,1/2,1/2,1];
[row,col]=size(A);
%判断矩阵一致性检验
n=col;
maxlam=max(eig(A));
RI=[0 0 0.58 0.90 1.12 1.24 1.32 1.41 1.45];
CI=(maxlam-n)/(n-1);
CR=CI/RI(n);
%判断矩阵确定权重
for i=1:col
sumcol=sum(A(:,i));
for j=1:row
A(j,i)=A(j,i)/sumcol;
end
end
weig=zeros(row,1);
for i=1:row
sumrow=sum(A(i,:));
weig(i)=sumrow/n;
end
%各个指标归一化 按列单位化
data= [1686.4 3183 12000 397
903.6 1916.4 3439.6 43
837.6 817.6 4748 1159
824.9 1296.4 12000 442
2110.2 1465.7 6199.5 228];
[rowd,cold]=size(data);
for i=1:cold
sumcold=sum(data(:,i));
for j=1:rowd
data(j,i)=data(j,i)/sumcold;
end
end
%按权重计算分数
score=data*weig;
projectNames={'老番茄','何同学','木鱼水心','凉风','罗翔'};
figure;
bar(score);%条形图
set(gca, 'XTickLabel', projectNames); %每个条形图标签
xlabel('博主');
ylabel('加权总分');
title('得分');
grid on; % 网格线