MATLAB: Can’t save rule in new matrix

save rule in new matrix

Hi I have two matrix
A= [0.1102 0.0612 0.1946
0.1812 0.1469 0.0379
0.1738 0.0037 0.0906]
B= [0.1116 0.1387 0.0650
0.0724 0.0913 0.1516
0.0765 0.1705 0.1225]
I want to create matrix C from matrix A and B. Matrix C has 6 rows and 3 column.
row 1 of Matrix C is like row 1 of Matrix A but Row 2 of Matrix C is like row 1 of Matrix B.again row 3 of matrix C is like row 2 of matrix A and row 4 of matrix C is like row 2 of matrix B. and this rule repeat for other rows.
the original of my matrix is very large and this is an example.
I write the code but I cant save C in matrix.
for i=1:m*n
C=[A(i);B(i)]
end

Best Answer

Concatenate horizontally, transpose, reshape and transpose does it:
C = reshape([A B]', size(A, 2), [])'
C =
0.1102 0.0612 0.1946
0.1116 0.1387 0.0650
0.1812 0.1469 0.0379
0.0724 0.0913 0.1516
0.1738 0.0037 0.0906
0.0765 0.1705 0.1225