How to extract all the diagonal blocks of size 2x2 from NxN matrix?
조회 수: 2 (최근 30일)
이전 댓글 표시
Suppose we have a square matrix A of size 40 x40 as follow
How to extract all the diagonal blocks of size 2 x 2 from the matrix A ?
댓글 수: 0
답변 (1개)
Walter Roberson
2019년 3월 21일
temp = repmat({ones(2,2)}, 1, 20);
L = blkdiag(temp{:});
output = reshape(A(L), 2, 2, []);
This will produce a 2 x 2 x 20 result where each pane is one of the 2 x 2 block diagonals.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Operating on Diagonal Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!