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

조회 수: 5 (최근 30일)
How do I create a function that interweaves two vectors of 1xN dimensions?

채택된 답변

Evgeny Pr
Evgeny Pr 2013년 1월 24일
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
  댓글 수: 1
Walter Roberson
Walter Roberson 2013년 1월 24일
This would leave 0s untouched in places where one vector was shorter than the other. Which might be fine or might not be.
Note that in general it would be better to supply class(v1) as the final argument of zeros(), to handle the situation where the vectors were (e.g.) uint8

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Walter Roberson
Walter Roberson 2013년 1월 23일
V = reshape([V1;V2], 1, []);
  댓글 수: 2
Jose
Jose 2013년 1월 24일
That only works for vectors with the same dimensions. How do you account for ones without?
Walter Roberson
Walter Roberson 2013년 1월 24일
Then the two vectors would not be "1xN dimensions" and it would be a different Question -- one would immediately attract questions about what it meant to interweave if the two vectors were not the same size.

댓글을 달려면 로그인하십시오.

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by