我是MATLAB的新手。我通过使用FOR循环生成了n个(3 x 1)的较小矩阵。所有矩阵都有随机值。现在我想连接所有值以形成一个LARGE矩阵'M'。请在下面查看我的代码。
n= input('please input the number of criterias \n');
for k=1:1:n
fprintf('Please input the %d X %d decision matrix for no %d Criteria \n', n,n,k);
m=input('');
S=sum(m);
for i=1:1:n
for j=1:1:n
m(i,j)= m(i,j)/S(j);
end
end
rS=sum(m,2);
pk=rS/n;
fprintf('the prioritized matrix for no %d criteria ) is ::\n',k);
disp(pk);
end`
please input the number of criterias
3
Please input the 3 X 3 decision matrix for no 1 Criteria
[1 2 3 ; 4 5 6; 7 8 9]
the prioritized matrix for no 1 criteria ) is ::
0.1278
0.3333
0.5389
Please input the 3 X 3 decision matrix for no 2 Criteria
[4 5 6; 3 7 9; 8 1 4]
the prioritized matrix for no 2 criteria ) is ::
0.3224
0.4040
0.2736
Please input the 3 X 3 decision matrix for no 3 Criteria
[1 5 4 ; 2 7 0; 3 6 7]
the prioritized matrix for no 3 criteria ) is ::
0.2694
0.2407
0.4899
M = [ .1278 .3224 .2644 ;
.3333 .4040 .2407 ;
.5839 .2736 .4899 ]
答案 0 :(得分:0)
很难看到你的循环发生了什么,但这个例子应该有所帮助。使用逗号(添加列)或分号(添加行)完成矩阵连接。因此,如果您有三个大小为1x3的行矩阵,它们看起来像:
m1=[.1278 .3224 .2644]
m2=[.3338 .4040 .2407]
m3=[.5839 .2736 .4899]
你可以制作一个3x3矩阵M用小冒号连接你的小矩阵:
M=[m1;m2;m3]
看起来像这样:
M =
0.12780 0.32240 0.26440
0.33380 0.40400 0.24070
0.58390 0.27360 0.48990