查看: 333|回复: 2|关注: 0

[已解决] 矩阵运算的问题

[复制链接]

新手

7 麦片

财富积分


050


1

主题

3

帖子

0

最佳答案
output =[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0;
    1,0,0,0,0,0,0,0,0,0,0,0,0,0,0;
    1,0,0,0,0,0,0,0,0,0,0,0,0,0,0;
    1,0,0,0,0,0,0,0,0,0,0,0,0,0,0;
    0,1,0,0,0,0,0,0,0,0,0,0,0,0,0;
    0,1,0,0,0,0,0,0,0,0,0,0,0,0,0;
    0,1,0,0,0,0,0,0,0,0,0,0,0,0,0;
    0,1,0,0,0,0,0,0,0,0,0,0,0,0,0;
    0,0,1,0,0,0,0,0,0,0,0,0,0,0,0;
    0,0,1,0,0,0,0,0,0,0,0,0,0,0,0;
    0,0,1,0,0,0,0,0,0,0,0,0,0,0,0;
    0,0,1,0,0,0,0,0,0,0,0,0,0,0,0;
    0,0,0,1,0,0,0,0,0,0,0,0,0,0,0;
    0,0,0,1,0,0,0,0,0,0,0,0,0,0,0;
    0,0,0,1,0,0,0,0,0,0,0,0,0,0,0;
    0,0,0,1,0,0,0,0,0,0,0,0,0,0,0;
    0,0,0,0,1,0,0,0,0,0,0,0,0,0,0;
    0,0,0,0,1,0,0,0,0,0,0,0,0,0,0;
    0,0,0,0,1,0,0,0,0,0,0,0,0,0,0;
    0,0,0,0,1,0,0,0,0,0,0,0,0,0,0;
    0,0,0,0,0,1,0,0,0,0,0,0,0,0,0;
    0,0,0,0,0,1,0,0,0,0,0,0,0,0,0;
    0,0,0,0,0,1,0,0,0,0,0,0,0,0,0;
    0,0,0,0,0,1,0,0,0,0,0,0,0,0,0;
    0,0,0,0,0,0,1,0,0,0,0,0,0,0,0;
    0,0,0,0,0,0,1,0,0,0,0,0,0,0,0;
    0,0,0,0,0,0,1,0,0,0,0,0,0,0,0;
    0,0,0,0,0,0,1,0,0,0,0,0,0,0,0;
    0,0,0,0,0,0,0,1,0,0,0,0,0,0,0;
    0,0,0,0,0,0,0,1,0,0,0,0,0,0,0;
    0,0,0,0,0,0,0,1,0,0,0,0,0,0,0;
    0,0,0,0,0,0,0,1,0,0,0,0,0,0,0;
    0,0,0,0,0,0,0,0,1,0,0,0,0,0,0;
    0,0,0,0,0,0,0,0,1,0,0,0,0,0,0;
    0,0,0,0,0,0,0,0,1,0,0,0,0,0,0;
    0,0,0,0,0,0,0,0,1,0,0,0,0,0,0;
    0,0,0,0,0,0,0,0,0,1,0,0,0,0,0;
    0,0,0,0,0,0,0,0,0,1,0,0,0,0,0;
    0,0,0,0,0,0,0,0,0,1,0,0,0,0,0;
    0,0,0,0,0,0,0,0,0,1,0,0,0,0,0;
    0,0,0,0,0,0,0,0,0,0,1,0,0,0,0;
    0,0,0,0,0,0,0,0,0,0,1,0,0,0,0;
    0,0,0,0,0,0,0,0,0,0,1,0,0,0,0;
    0,0,0,0,0,0,0,0,0,0,1,0,0,0,0;
    0,0,0,0,0,0,0,0,0,0,0,1,0,0,0;
    0,0,0,0,0,0,0,0,0,0,0,1,0,0,0;
    0,0,0,0,0,0,0,0,0,0,0,1,0,0,0;
    0,0,0,0,0,0,0,0,0,0,0,1,0,0,0;
    0,0,0,0,0,0,0,0,0,0,0,0,1,0,0;
    0,0,0,0,0,0,0,0,0,0,0,0,1,0,0;
    0,0,0,0,0,0,0,0,0,0,0,0,1,0,0;
    0,0,0,0,0,0,0,0,0,0,0,0,1,0,0;
    0,0,0,0,0,0,0,0,0,0,0,0,0,1,0;
    0,0,0,0,0,0,0,0,0,0,0,0,0,1,0;
    0,0,0,0,0,0,0,0,0,0,0,0,0,1,0;
    0,0,0,0,0,0,0,0,0,0,0,0,0,1,0;
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,1;
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,1;
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,1;
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,1;
    ]';
这个是15*60 的矩阵
以上的矩阵怎么用函数公示表达出来??

我自己想的是输入
B = [1, 1 , 1, 1 ;] ;
A = diag([B B B B B B B B B B B B B B B]);
以为会得到前4列的第一行是1           的 15*4 的矩阵
得到15*15的对角矩阵 每一列都是4 个元素
但是得出来的是60*60的矩阵
请问怎么做,才能得到想要的矩阵。


论坛优秀回答者

7

主题

1502

帖子

349

最佳答案
  • 关注者: 62
发表于 2018-9-13 15:40:15 | 显示全部楼层 |此回复为最佳答案
你需要的是blkdiag:
  1. B = [1 1 1 1];
  2. A = blkdiag(B,B,B,B,B,B,B,B,B,B,B);
复制代码

或者
  1. B = [1 1 1 1];
  2. [c{1:15}] = deal(B);
  3. A = blkdiag(c{:});
复制代码
多看帮助文档
说明你的matlab版本

新手

7 麦片

财富积分


050


1

主题

3

帖子

0

最佳答案
 楼主| 发表于 2018-9-14 14:32:26 | 显示全部楼层
实在是太感谢了
:):lol
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

站长推荐上一条 /3 下一条

快速回复 返回顶部 返回列表