MATLAB: How i can insert ‘L’ number of zeros after each element in a vector

MATLABvector

if x = [1,2,3,4,…] and L=3
sol: y = [1,0,0,2,0,0,3,0,0,4,…]
thanks

Best Answer

>> x = [1,2,3,4];
>> L = 3;
>> y = reshape([x;zeros(L,numel(x))],1,[])
y =
1 0 0 0 2 0 0 0 3 0 0 0 4 0 0 0