필터 지우기
필터 지우기

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

조회 수: 4 (최근 30일)
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 CenterFile Exchange에서 Operating on Diagonal Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by