Defining a matrix of moving constants using a loop

Hello everyone,
i want to define a matrix of size nxn with first row having 5 constants i.e. A(1,1:5) are constants..other coefficients are zeros...and then put start these constants from the second column in the second row...this going for n rows...for eg
if I have A (1,:) = [1 2 3 4 5 0 0 ... n0] as the first row,
the next row would be
A (2,:) = [0 1 2 3 4 5 0 ..0 0 n0]
this goes on until
A (n,:) = [0 0 ... 0 1 2 3 4 5]
i presume this is a looping issue...can any one guide how would I define this loop?
Thanks in advance for your help

回答 (1 件)

Jos (10584)
Jos (10584) 2014 年 6 月 4 日

2 投票

A = 1:5
n = 4
B = triu(toeplitz(A, [A zeros(1,n)]))

この質問は閉じられています。

質問済み:

2014 年 6 月 4 日

閉鎖済み:

2021 年 8 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by