MATLAB: How is it possible to insert column to the right/left of a vector in different places for some required times

errorfor loopinsert elementmatrixvector

Imagine there is a vector like below and you want to insert a number(a column) in some special places of that vector :
A = [1 1 2 3 1 2 3 3 2 1 2 1 1 1]
the required vector :
B = [1 4 1 4 2 3 1 4 2 3 3 2 1 4 2 1 4 1 4 1 4]
in fact I wanted to find "1" in vector "A" and then after the column of that "1", add a new column with value "4" for the required vector "B" without losing the main data. I just could do it for the first 1 in the vector A and for others I get an error :
for i=1:length(A)
if A(i)==1
B=[A(:,1:A(i)==1) 4 A(:,A(i+1):end)]
end
end
the error : Index exceeds matrix dimensions.

Best Answer

B=strrep(A,1,[1,4])