Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

MATLAB The one on the bottom is the \"previous\" one they are referring to. No l

ID: 3909789 • Letter: M

Question

MATLAB The one on the bottom is the "previous" one they are referring to. No loops, for, while, switcj, i = counting.

Interleave advanced Modify the function interleave, written in a previous assignment, to create a function called interleaveMod. interleaveMod interleaves two row arrays of different lengths named A2 and B2. If the function runs out of elements in one of the row arrays, the remaining elements of the resulting array keeps the remaining elements from the longer row array. The function should work for rows of any length. Hint: The internal functions length and min, and array indexing should be used. Restrictions: For and while loops should not be used. Ex: >> A2- [1, 2, 3, 4, 5, 6] , A2 [le, 30j, ?3s interleaveMod(A2 , B2) B2_ 20, 2 4 6 B2 10 20 30 C3 1 10 220 3 30 456

Explanation / Answer

function [A3] = interleaveMod(A1, A2)
minLen = min(length(A1), length(A2));
C1 = [A1(1:minLen); A2(1:minLen)];
A3 = C1(1:1:end);
A3 = [A3, A1(minLen+1:end), A2(minLen+1:end)]
end
  

Output:

>> A1 = 1:2:10

A1 =

1 3 5 7 9

>> A2 = 0:2:20

A2 =

0 2 4 6 8 10 12 14 16 18 20

>> interleaveMod(A1,A2)

A3 =

1 0 3 2 5 4 7 6 9 8 10 12 14 16 18 20


ans =

1 0 3 2 5 4 7 6 9 8 10 12 14 16 18 20

>> A2 = 0:2:10

A2 =

0 2 4 6 8 10

>> A1 = 1:2:20

A1 =

1 3 5 7 9 11 13 15 17 19

>> interleaveMod(A1,A2)

A3 =

1 0 3 2 5 4 7 6 9 8 11 10 13 15 17 19


ans =

1 0 3 2 5 4 7 6 9 8 11 10 13 15 17 19

>>