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 !

 채택된 답변

Birdman
Birdman 2018년 3월 24일

0 개 추천

>>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

댓글 수: 1

jia ying
jia ying 2018년 3월 24일
Thanks a lot, your help is appreciated !
*ps: new to matlab

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Operating on Diagonal Matrices에 대해 자세히 알아보기

질문:

2018년 3월 24일

댓글:

2018년 3월 24일

Community Treasure Hunt

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

Start Hunting!

Translated by