How to shift the element in diagonal matrix
9 views (last 30 days)
Show older comments
As question mentioned, I created a matrix
v = [4 5 6 7]
diag(v)
then, I would like to have a matrix as [0 4 0 0; 0 0 5 0; 0 0 0 6; 7 0 0 0] also [0 0 0 4; 5 0 0 0; 0 6 0 0; 0 0 7 0] by using the command diag, is there any way to do?
Thank you !
0 Comments
Accepted Answer
Birdman
on 24 Mar 2018
>>circshift(diag(v),1,2)
0 4 0 0
0 0 5 0
0 0 0 6
7 0 0 0
>>circshift(diag(v),-1,2)
0 0 0 4
5 0 0 0
0 6 0 0
0 0 7 0
More Answers (0)
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!