MATLAB: How to combine 2 matrices (or vectors) element by element in order (with different sizes)

concatenate

How can I combine 2 matrices A and B into one so that the new matrix C = element 1 of A, followed by element 1 of B, then element 2 of A, element 2 of B, etc? Note that vectors A and B are randomly generated and the size might be different.
For example, A = [x1 x2 x3 …], B = [y1 y2 y3 …] and then C=[x1 y1 x2 y2 x3 y3 …]
Thank you.

Best Answer

A=1:3
B=4:6
C=[A;B]
C=C(:)'
%or
C=reshape([A;B],1,[])