Azzera filtri
Azzera filtri

Can't save rule in new matrix

1 visualizzazione (ultimi 30 giorni)
fatema saba
fatema saba il 11 Gen 2015
Commentato: fatema saba il 11 Gen 2015
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

Risposta accettata

Guillaume
Guillaume il 11 Gen 2015
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

Più risposte (0)

Categorie

Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by