MATLAB: How can i get a matrix from an array like this:

control flowhomework

Starting with
a = [12 21 32];
I would like to get this:
M = [12 21 32; 21 32 12; 32 12 21];
with size and length fun. only
Is it some kind of loop???

Best Answer

a = [12 21 32 42];
n=length(a)
M=a
for k=1:n-1
c=a(1)
a(1:end-1)=a(2:end)
a(end)=c
M=[M;a]
end