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?
Show older comments
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.
Accepted Answer
More Answers (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.
Categories
Find more on Matrices and Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!