Inserteing从几个矩阵的元素,以形成一个大的矩阵在MATLAB [英] Inserteing the elements from several matrices to form a Large matrix in MATLAB

查看:229
本文介绍了Inserteing从几个矩阵的元素,以形成一个大的矩阵在MATLAB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的MATLAB。我已经使用FOR循环产生的n个数字(3×1)小矩阵。所有矩阵有。现在我要来连接所有值,形成一个大阵'M'请看看我的codeS下面的随机值。

  N =输入('请输入审核规定的\数N');
对于k = 1:1:N
    fprintf中(请输入%深x%D决策矩阵%d号标准\ N',N,N,K);
    米=输入('');
    S =总和(米);
对于i = 1:1:N
    对于j = 1:1:n的
    米(I,J)=米(I,J)/ S(j)条;
    结束
结束
RS =总和(米,2);
 PK = RS / N;
 fprintf中(优先矩阵%d号标准)是:: \ N',K);
 DISP(PK);
 end`
 

和命令窗口中显示的O / P这样

 请输入审核规定的数量
3
请输入3×3的决策矩阵1号标准
[1 2 3; 4 5 6; 7 8 9]
优先矩阵1号标准)是::
    0.1278
    0.3333
    0.5389

请输入3×3的决策矩阵为2号标准
[4 5 6; 3 7 9; 8 1 4]
优先矩阵为无2条件)是::
    0.3224
    0.4040
    0.2736

请输入3×3的决策矩阵3号标准
[1 5 4; 2 7 0; 3 6 7]
优先矩阵没有3标准)是::
    0.2694
    0.2407
    0.4899
 

现在我想,以形成一个大规模矩阵M附加从所有的较小所得矩阵(优先矩阵)获得的值。 M应是这样

  M = [0.1278 0.3224 0.2644;
      0.3333 0.4040 0.2407;
      0.5839 0.2736 0.4899]
 

现在请指引我,我怎么能做到这一点的一个有效的方法?
注:M并不总是一个3X3矩阵,它是一个巨大的订单尺寸(以防万一40X40)在我真正的项目,而且其并不总是固定的,这取决于用户的输入,即N。我感到非常抱歉previous格式化的错误。

解决方案

很难看到什么是你的循环怎么回事,但这个例子应该有所帮助。矩阵拼接完成用逗号(添加列)或分号(添加行)。所以,如果你有大小1×3的三排阵看起来像:

  M1 = [1278 0.3224 0.2644]
M2 = [3338 0.4040 0.2407]
M3 = [5839 0.2736 0.4899]
 

您可以做一个3×3矩阵M​​串联的小矩阵的分号:

  M = [M1,M2,M3]
 

这看起来是这样的:

  M =

   0.12780 0.32240 0.26440
   0.33380 0.40400 0.24070
   0.58390 0.27360 0.48990
 

I am a new to MATLAB. I have generated n numbers of smaller matrices of (3 x 1 ) by using a FOR loop. All the matrices are having random values .Now I want to concatenate all the values to form a LARGE matrix 'M'
Please check out my codes below .

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`

and the Command window shows the O/p like this

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

Now I want to append the values obtained from all the smaller resultant matrices (prioritized matrices) in order to form a LARGE MATRIX 'M'. 'M' shall look like this

M = [ .1278 .3224 .2644 ;
      .3333 .4040 .2407 ;
      .5839 .2736 .4899 ] 

Now Please guide me how could i do this in an efficient way ?
NOTE : 'M' is not always a 3X3 matrix , Its a huge order dimension (arround 40X40) in my real project and moreover Its not always fixed and It depends upon the USER INPUT i.e 'n' . I am extremely sorry for the previous Formatting mistakes.

解决方案

Hard to see what is going on with your loops, but this example should help. Matrix concatenation is done with commas (to add columns) or semi-colons (to add rows). So if you have three row matrices of size 1x3 that look like:

m1=[.1278 .3224 .2644]
m2=[.3338 .4040 .2407]
m3=[.5839 .2736 .4899]

you can make a 3x3 matrix M concatenating your small matrices with semi-colons:

M=[m1;m2;m3]

that looks like this:

M =

   0.12780   0.32240   0.26440
   0.33380   0.40400   0.24070
   0.58390   0.27360   0.48990

这篇关于Inserteing从几个矩阵的元素,以形成一个大的矩阵在MATLAB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆