필터 지우기
필터 지우기

Create a matrix using offset elements of a vector

조회 수: 9 (최근 30일)
WeiShan Ng
WeiShan Ng 2020년 6월 25일
댓글: WeiShan Ng 2020년 6월 26일
Let say I have a vector v = [v1, v2, v3], I would like to create a non-square matrix putting the vector v as tridiagonal elements like this ,
matrix = [v1, v2, v3, 0, 0, 0,..., 0;
0 , v1,v2,v3, 0, 0 ,...,0;
0 , 0, v1,v2,v3,0,.....,0;]
I know there's a diag command but it's only for square matrix. What's the way of creating a non-square matrix?

채택된 답변

Kanika Gupta
Kanika Gupta 2020년 6월 25일
Try blktridiag:
A = blktridiag([1;2],[3;4],[5;6],4);
full(A)
ans =
1 5 0 0
2 6 0 0
3 1 5 0
4 2 6 0
0 3 1 5
0 4 2 6
0 0 3 1
0 0 4 2
Run help blktridiag for more info
  댓글 수: 1
WeiShan Ng
WeiShan Ng 2020년 6월 26일
Thank you. This is exactly what I am looking for!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by