MATLAB: Repeating numbers in matrix

repeat columns

I need to generate a input variation in the form
% For wxample
col1 :2 4 6 2 4 6 2 4 6 2 4 6
col2 :1 1 1 1 1 1 2 2 2 2 2 2
col2 :5 5 5 5 5 5 5 5 5 5 5 5
is there any shorter way to do it without looping.

Best Answer

col1=repmat(2:2:6,1,3)
col2=reshape(repmat(1:2,6,1),1,[])
col3=5*ones(1,12)
Read the documentation
doc repmat
doc reshape