How to create a 3 diagonal matrix with blocks

1 回表示 (過去 30 日間)
Johan De Jager
Johan De Jager 2022 年 6 月 26 日
コメント済み: Voss 2022 年 6 月 27 日
I would like to create a matrix of the following form, ideally without having to use a loop as its size can become rather large:
basically it is an 2N x 2N matrix with a double wide 3 diagonal.
If anyone can provide some assistance in this it would be much appreciated.

採用された回答

Voss
Voss 2022 年 6 月 26 日
編集済み: Voss 2022 年 6 月 26 日
N = 7;
M = zeros(2*N,N+2);
M( 1+(2*N+2)*(0:N-1) + reshape([0 1]+[0;1;2]*2*N,[],1) ) = 1;
disp(M);
1 1 1 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 1 1 1
  2 件のコメント
Johan De Jager
Johan De Jager 2022 年 6 月 27 日
Perfect, this should work wonders.
Thank you very much
Voss
Voss 2022 年 6 月 27 日
You're welcome!

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

その他の回答 (0 件)

カテゴリ

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

タグ

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by