Creating triangular matrix from a vector (with a twist)

I have a vector v=[a b c d] and I want to (efficiently) create a matrix of the form : M=[a 0 0 0 ; b a 0 0 ; c b a 0 ; d c b a ]. I am experimenting with "diag" function but it does not seem to be very efficient. Any thoughts?

 채택된 답변

Matt J
Matt J 2015년 9월 7일
>> toeplitz([1 2 3 4],[1,0,0,0])
ans =
1 0 0 0
2 1 0 0
3 2 1 0
4 3 2 1

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

질문:

2015년 9월 7일

답변:

2015년 9월 7일

Community Treasure Hunt

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

Start Hunting!

Translated by