Fastest & most effective way to create this matrix:

1 次查看(过去 30 天)
Hey there, I have been searching for hours for a good solution & not found one yet. I need to create this matrix (6X6):
A = 0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 1 2 3
0 0 0 4 5 6
0 0 0 7 8 9
It must be in an effective & short way. Thank you if anyone can help with this one.

采纳的回答

Andrei Bobrov
Andrei Bobrov 2014-12-19
one way
a =[1 2 3
4 5 6
7 8 9];
out = kron([0 0 ; 0 1],a);

更多回答(1 个)

Orion
Orion 2014-12-19
编辑:Orion 2014-12-19
clear A;
A(4:6,4:6) = reshape(1:9,3,3)'
  2 个评论
Eitan
Eitan 2014-12-19
Thank you! I actually used that code because it looks shorter. you guys are great!

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Shifting and Sorting Matrices 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by