开发者

Splice matlab vectors

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

开发者_C百科
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 quickly? My x's and y's are pretty big. Thanks!


You can do this via some reshaping

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(:)'
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜