How to create a matrix, table or a cell where in odd columns variables from matrix A and in even columns variabls from matrix B will be stored?
Afficher commentaires plus anciens
For instance, I have two matrices A = ones(5,24) and B = zeros(5,24), I need to create a matrix 'C', where the first column of 'C' will consist of elements of A(:,1), the second column of 'C' will consist of B(:,1), the third column of 'C' will consist of elements of A(:,2), the fourth column of 'C' will consist of B(:,2) and so on.
Also, I'd like to know how the same can be applied to cell arrays and how the table of the same format could be constructed from matrices? For loops are ok.
Many thanks.
Réponse acceptée
Plus de réponses (1)
C = reshape( [A; B], [5 48] )
will interleave columns of A and B. doesn't matter if they are numeric or cell arrays.
For creating a table you can just do that from the result unless you mean A and B are also both tables.
Catégories
En savoir plus sur Matrices and Arrays dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!