MATLAB: How to cycle through a vector to create a matrix

MATLABmatricesvertcat

A=[a,b,c,d,0,0,0,0…,0] 1xN vector
Using vector "A", I want to create an NxN matrix such that each row is the previous row with its elements fliped one at a time. That is, I want to create:
[a,b,c,d,0,0,0,…,0;
0,a,b,c,d,0,0,,…0;
0,0,a,b,c,d,0,…0;
…..
0,…0,0,0,a,b,c,d]
I could use a "for statement" using A=[A(end), A(1:end-1)] and vertcat(). But is there a more efficient and elegant way of doing this? Thanks

Best Answer

I am not certain what result you want.
Try this:
syms a b c d
N = 10-4;
Av = [a b c d 0 0 0 0 0 0];
for k = 0:N
A(k+1,:) = circshift(Av,k,2)
end
producing:
A =
[a, b, c, d, 0, 0, 0, 0, 0, 0]
[0, a, b, c, d, 0, 0, 0, 0, 0]
[0, 0, a, b, c, d, 0, 0, 0, 0]
[0, 0, 0, a, b, c, d, 0, 0, 0]
[0, 0, 0, 0, a, b, c, d, 0, 0]
[0, 0, 0, 0, 0, a, b, c, d, 0]
[0, 0, 0, 0, 0, 0, a, b, c, d]
.