Matrix Connecting Vectors

I have two matlab vectors. The first has N elements, the other has k*N I know what k , and I want to connect the lists so that each element from the first vector appears before the corresponding elements of k from the next vector. For instance:

 k = 3 x = [1 5 9] y = [2 3 4 6 7 8 10 11 12] 

should be combined to look like this:

 z = [1 2 3 4 5 6 7 8 9 10 11 12] 

Is there an easy way to do this fast? My x and y are pretty big. Thanks!

+4
source share
1 answer

You can do this with some adjustment

 k = 3 x = [1 5 9] y = [2 3 4 6 7 8 10 11 12] %# make a k-by-n array z = reshape(y,k,[]); %# catenate with x z = [x;z]; %# reorder z = z(:)' 
+7
source

All Articles