フィルターのクリア

Extend a matrix diagonally

4 ビュー (過去 30 日間)
WARRIOR24
WARRIOR24 2021 年 3 月 24 日
編集済み: Matt J 2021 年 3 月 24 日
I am trying to exted a 4 x 4 matrix to... lets say a 9 x 9 matrix while keeping the diagonal numbers. BUT the 9 x 9 matrix can easily be changed to 11 x 11 and so and so on. I looking for a for loop that will be to scale this matrix depending on input numbers.
2 1 0 0
1 2 1 0
0 1 2 1
0 0 1 2
2 1 0 0 0 0 0 0 0
1 2 1 0 0 0 0 0 0
0 1 2 1 0 0 0 0 0
0 0 1 2 1 0 0 0 0
0 0 0 1 2 1 0 0 0
0 0 0 0 1 2 1 0 0
0 0 0 0 0 1 2 1 0
0 0 0 0 0 0 1 2 1
0 0 0 0 0 0 0 1 2

回答 (2 件)

Matt J
Matt J 2021 年 3 月 24 日
編集済み: Matt J 2021 年 3 月 24 日
No need for a loop:
n=9;
result=toeplitz([2 1 zeros(1,n-2)])
result = 9×9
2 1 0 0 0 0 0 0 0 1 2 1 0 0 0 0 0 0 0 1 2 1 0 0 0 0 0 0 0 1 2 1 0 0 0 0 0 0 0 1 2 1 0 0 0 0 0 0 0 1 2 1 0 0 0 0 0 0 0 1 2 1 0 0 0 0 0 0 0 1 2 1 0 0 0 0 0 0 0 1 2
n=11;
result=toeplitz([2 1 zeros(1,n-2)])
result = 11×11
2 1 0 0 0 0 0 0 0 0 0 1 2 1 0 0 0 0 0 0 0 0 0 1 2 1 0 0 0 0 0 0 0 0 0 1 2 1 0 0 0 0 0 0 0 0 0 1 2 1 0 0 0 0 0 0 0 0 0 1 2 1 0 0 0 0 0 0 0 0 0 1 2 1 0 0 0 0 0 0 0 0 0 1 2 1 0 0 0 0 0 0 0 0 0 1 2 1 0 0 0 0 0 0 0 0 0 1 2 1

Matt J
Matt J 2021 年 3 月 24 日
編集済み: Matt J 2021 年 3 月 24 日

カテゴリ

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

タグ

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by