Awkward but overall single-line
n = 3; %number of elements in A; m = 5; %repetitions A = (1:n); B = full( spdiags( repmat(A(:),1,m)' , 1-(1:n) , n+m-1, m) )
returns:
B = 1 0 0 0 0 2 1 0 0 0 3 2 1 0 0 0 3 2 1 0 0 0 3 2 1 0 0 0 3 2 0 0 0 0 3
Alternatively improved, general version of rubenvb solution
B = toeplitz( [A(:);zeros(m-1,1)] , zeros(1,m) )
in both cases, A can be either a row or column vector.
A faster solution (2x ratio) is the first with spdiags !
Edit: even more inconvenient, but up to 10 times faster (it depends on n, m) than toeplitz -approach:
B = reshape( [repmat([A(:);zeros(m,1)],m-1,1) ; A3(:)] ,[],m )
source share