How to produce square matrix in this form
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Mohammad Ezzad Hamdan
am 11 Mai 2021
Kommentiert: Mohammad Ezzad Hamdan
am 11 Mai 2021
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.
0 Kommentare
Akzeptierte Antwort
Stephan
am 11 Mai 2021
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
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Resizing and Reshaping Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!