Simple vector question.
古いコメントを表示
function vec = weave(in1, in2)
a = length(in1);
b = length(in2);
l = max(a,b);
vec = zeros(1, 2.*l);
vec(1:2:2.*a) = in1;
vec(2:2:2.*b) = in2;
I'm trying to create a function that a larger vector where the values in the first vector are inserted in the odd indices and the values in the second vector are inserted in the even indices(weave). The condition is that f the two vectors are not the same length, the shorter vector should be extended by adding consecutive integers to the end. I figured out how to put put those vectors into the position but I couldn't figure out how to extend shorter vector by adding consecutive integers(I could only figure out to fill that with same integers.) What would be the solution?
- For example, [5 4 1 8 9 1] [7 3 5 5] becomes [5 7 4 3 1 5 8 5 9 6 1 7] instead of [5 7 4 3 1 5 8 5 9 0 1 0].
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Call Web Services from MATLAB Using HTTP についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!