Can't save rule in new matrix

1 次查看(过去 30 天)
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

采纳的回答

Guillaume
Guillaume 2015-1-11
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by