MATLAB: Creating a specific lower rectangular matrix

matrix manipulationrectangular matrix

Hello Matlab experts!
I'm interested in creating a specific lower rectangular matrix while avoiding loops.
Step 1: I create the following column vector:
[ A1 A2 A3 . . . . An ]'
Where n is a predetermined integer (changes from one simulation to another).
Step 2: I create the following matrix:
A1 A1 A1 A1 . . . . A1
A2 A2 A2 A2 . . . . A2
A3 A3 A3 A3 . . . . A3
. . .
An An An An . . . . An
Step 3: I want to perform the following shifts: Shift the second column one step down, Shift the third column two steps down, etc. So eventually I'll get the following matrix:
A1 An An-1 An-2 . . . . A2
A2 A1 An An-1 . . . . A3
A3 A2 A1 An . . . . A4
A4 A3 A2 A1 . . . . A5
. . .
An An-1 An-2 An-3 . . . . A1
Step 4: I use the 'tril' function to get the matrix I'm interested in, which is:
A1 0 0 0 . . . . 0
A2 A1 0 0 . . . . 0
A3 A2 A1 0 . . . . 0
A4 A3 A2 A1 . . . . 0
. . .
An An-1 An-2 An-3 . . . . A1
I need assistance with performing step 3.
Maybe there are better ways to create this matrix, let me know.
Thanks, Amital

Best Answer

A = 1:5;
out = tril(toeplitz(A))
Related Question