How to extract all the diagonal blocks of size 2x2 from NxN matrix?

조회 수: 2 (최근 30일)
riya sharma
riya sharma 2019년 3월 21일
답변: Walter Roberson 2019년 3월 21일
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 ?

답변 (1개)

Walter Roberson
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.

카테고리

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