Filter löschen
Filter löschen

Extend a matrix diagonally

4 Ansichten (letzte 30 Tage)
WARRIOR24
WARRIOR24 am 24 Mär. 2021
Bearbeitet: Matt J am 24 Mär. 2021
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

Antworten (2)

Matt J
Matt J am 24 Mär. 2021
Bearbeitet: Matt J am 24 Mär. 2021
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 am 24 Mär. 2021
Bearbeitet: Matt J am 24 Mär. 2021

Kategorien

Mehr zu Operating on Diagonal Matrices finden Sie in Help Center und File Exchange

Tags

Produkte


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by