MATLAB: How to create a function that interweaves two vectors of 1xN dimensions

interweave

How do I create a function that interweaves two vectors of 1xN dimensions?

Best Answer

  • As one of the ideas:
    v1 = [1, 2, 3, 4]
    v2 = [5, 6, 7, 8, 9, 10]
    lv1 = length(v1)
    lv2 = length(v2)
    v = zeros(1,max(lv1,lv2)*2)
    v(1:2:lv1*2) = v1
    v(2:2:lv2*2) = v2