How to produce square matrix in this form

1 回表示 (過去 30 日間)
Mohammad Ezzad Hamdan
Mohammad Ezzad Hamdan 2021 年 5 月 11 日
How can I form a square matrix in this form regardless of its dimension. Note that the pattern; 1 will form after three 0 from the centre.

採用された回答

Stephan
Stephan 2021 年 5 月 11 日
k = 2; % define how often to repeat the pattern
result = toeplitz([5 repmat([1 0 0 0],1,k)])
gives:
result =
5 1 0 0 0 1 0 0 0
1 5 1 0 0 0 1 0 0
0 1 5 1 0 0 0 1 0
0 0 1 5 1 0 0 0 1
0 0 0 1 5 1 0 0 0
1 0 0 0 1 5 1 0 0
0 1 0 0 0 1 5 1 0
0 0 1 0 0 0 1 5 1
0 0 0 1 0 0 0 1 5
  1 件のコメント
Mohammad Ezzad Hamdan
Mohammad Ezzad Hamdan 2021 年 5 月 11 日
Thank you!!!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by