フィルターのクリア

Is there any way to put a small matrix diagonally into a larger one?

4 ビュー (過去 30 日間)
nafila aytija
nafila aytija 2016 年 4 月 4 日
コメント済み: Steven Lord 2016 年 4 月 4 日
ex: [1 2;3 4]
Big matrix :[1 2 0 0 0 0; 3 4 0 0 0 0; 0 0 1 2 0 0 0 0 3 4 0 0]

採用された回答

Chad Greene
Chad Greene 2016 年 4 月 4 日
A = [1 2; 3 4];
B = zeros(4,6);
B(1:2,1:2) = A;
B(3:4,3:4) = A;
  2 件のコメント
nafila aytija
nafila aytija 2016 年 4 月 4 日
thank you for your answer.but if I want to put a [2,2] matrix into a [200,200] matrix, how do I do that without using ''blkdiag?
Steven Lord
Steven Lord 2016 年 4 月 4 日
Create the matrix to be replicated on the diagonal
A = [1 2; 3 4];
Create a cell array with copies
C = repmat({A}, 1, 100);
Use the cell array to generate a comma-separated list and pass that list into blkdiag as 100 inputs
M = blkdiag(C{:});
Show the upper-left corner to see that it was created as you want.
M(1:10, 1:10)
Or in this case, since you want the same matrix to be repeated, an easier approach that doesn't require calling blkdiag with 100 inputs uses kron instead. It gives the same result as the blkdiag call as you can see from the result from isequal.
K = kron(eye(100), A);
isequal(K, M)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeOperating on Diagonal Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by