MATLAB: How to repeat indivisual element of a matrix

loopmatrix

Suppose, i have a matrix a=[1 0 1 1 0 0 1 1] and i want to repeat every element of this matrix by 3 times using for loop . as the new matrix will be b=[1 1 1 0 0 0 1 1 1 1 1 1 0 0 0 0 0 0 1 1 1 1 1 1] . How easily can solve??

Best Answer

for i=1:length(a)
b(3*i-2:3*i)=a(i);
end