Massive matrix, tridiagonal, ones()
3 views (last 30 days)
Show older comments
I need to transform this matrix, taking the three diagonal lines that have numbers and make them their own matrices. My matrix, however, is 124x124. I do not want to write a 1x123 matrix out that has 122 of the same number and 1 zero. Is there a way use ones() for this?
2 Comments
Adam Danz
on 15 Feb 2021
What 3 diagonal lines?
The description of the data and the description of the goal are not clear.
A demo using a smaller matrix would likely help.
Answers (1)
Jan
on 15 Feb 2021
A = [2 13 0 0 0 0;
1 2 13 0 0 0;
0 1 2 13 0 0;
0 0 1 2 13 0;
0 0 0 1 2 13];
d1 = diag(A, 0) % [2 2 2 2 2],'
d2 = diag(A, 1) % [13 13 13 13 13].'
d3 = diag(A, -1) % [1 1 1 1].'
I do not understand, how you want to get "[13 13 13 13 13 0]" (especially the trailing 0), "zeros(1,5)*2" (zeros times anything is still zeros?), and [0 1 1 1 1] (again the leading zero)?
See Also
Categories
Find more on Operating on Diagonal Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!