Create matrix with two matrices

1 vue (au cours des 30 derniers jours)
Eva Maria Leal Munoz
Eva Maria Leal Munoz le 27 Nov 2020
Réponse apportée : KSSV le 27 Nov 2020
Hello, I have two matrices that I want to combine to form another one as in the example below:
A = [1 2 3; 4 5 6;7 8 9]
B = [ 11 12 13;14 15 16;17 18 19]
Matrix = [1 2 3 ; 11 12 13 ; 4 5 6 ; 14 15 16 ; 7 8 9 ; 17 18 19]
Can anyone help me to solve it?
Many thanks,
Eva

Réponses (2)

KSSV
KSSV le 27 Nov 2020
A = [1 2 3; 4 5 6;7 8 9]
B = [ 11 12 13;14 15 16;17 18 19]
m = size(A,1)+size(B,2) ;
C = zeros(m,3) ;
C(1:2:end,:) = A ;
C(2:2:end,:) = B ;

Ameer Hamza
Ameer Hamza le 27 Nov 2020
Modifié(e) : Ameer Hamza le 27 Nov 2020
You can do something like this
A = [1 2 3; 4 5 6;7 8 9];
B = [ 11 12 13;14 15 16;17 18 19];
Matrix = zeros(size(A,1)+size(B,1), size(A,2));
Matrix(1:2:end, :) = A;
Matrix(2:2:end, :) = B;

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Produits


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by