MATLAB: Replacing Values of a Larger Matrix with that of a Smaller Matrix

matrixmatrix manipulation

I have a matrix A that looks like:
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
and a matrix B that looks like:
0 0
0 0
0 0
0 0
0 0
0 0
How can I create a new matrix C that looks like:
0 0 1 1 0 0 1 1 0 0
0 0 1 1 0 0 1 1 0 0
0 0 1 1 0 0 1 1 0 0
0 0 1 1 0 0 1 1 0 0
0 0 1 1 0 0 1 1 0 0
0 0 1 1 0 0 1 1 0 0
by inserting B into A and without using loops. Also if this is not possible, is there a way to create matrix C from matrix A?

Best Answer

b = mod( floor( (0:size( A, 2 )-1)/2 ), 2 ) ;
C = bsxfun( @times, A, b ) ;
Note that the way I define b=00110011.. is ... shows that I am tired!