Ask Question
29 November, 19:51

Write a function called interweave that takes in two vectors and then outputs a larger vector where the odd elements contain the values from the first vector, and the even elements contain the values from the second vector. if one vector is longer than the other, then the odd or even indices that wouldn't otherwise have values should be filled with zeros. for

+2
Answers (1)
  1. 29 November, 23:30
    0
    solution:

    function weaved=interweave (A, B)

    lenA=length (A);

    lenB=length (B);

    diff=abs (lenA-lenB);

    if lenA>lenB

    len=2*lenA;

    for j = (lenB+1) : (lenB+diff) %adds zero to shorter vector

    B (j) = 0;

    end

    else

    len=2*lenB;

    for j = (lenA+1) : (lenA+diff) %adds zero to shorter vector

    A (j) = 0;

    end

    end

    cnt=1;

    for i=1:2: (len-1)

    weaved (i) = A (cnt);

    weaved (i+1) = B (cnt);

    cnt=cnt+1;
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Write a function called interweave that takes in two vectors and then outputs a larger vector where the odd elements contain the values ...” in 📘 Mathematics if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers