基本信息
源码名称:AHP层次分析法
源码大小:2.14KB
文件格式:.rar
开发语言:MATLAB
更新时间:2020-03-12
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 2 元 
   源码介绍

%矩阵数据存在于x1.txt中
%层次数和每层因素个数放置于 x2.txt 文件中;
%打开文件 x2.txt : 该文件中第一个数字包含层次数(含目标层)
%第二行为每个层次中因素数
fid2 = fopen('x2.txt','r');
condition_array = fscanf(fid2,'%d',1);
condition = condition_array(1);

%读入每个层次的因素数
Cfactor = []; %因素
Cfactor = fscanf(fid2,'%d',[1,condition ]);
w = [];
%disp(Cfactor);
fclose(fid2);
%读取文件中的数据
current = 1; %Cfactor 的下标
fid = fopen('x3.txt','r');
     for i = 1:condition-1    %此处按照层次读取
         CVector = [];%组合权向量   
         for j = 1:Cfactor(current)  %此处读入数组个数
                tmp = [];
                for k = 1:Cfactor(current 1)    %此处读取数组元素行个数
                    tp = str2num(fgets(fid));
                    tmp = [tmp;tp];
                end
                %开始检查矩阵
                CCheck_array(tmp);
                %disp(tmp);
                %归一化 返回每个矩阵的特征向量
                current_vector = Normalized(tmp);
                %disp(current_vector);
                CVector = [CVector;current_vector];
         end
         w = Last(w,CVector);
         disp('当前CVector为:');
         disp(CVector);
         disp('当前w为:');
         disp(w);
    current = current 1;
    end
%找出权值最大的数以及下标    
tm = size(w);
max_num = 0;
ctmp = 1;
for i = 1:tm(2)
    if w(i) > max_num
        max_num = w(i);
        ctmp = i;
    end
end
disp('权值最大的数为:');
disp(max_num);
disp('最大权值下标为:');
disp(ctmp);
    
fclose(fid);