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

Interleave Write a function called interleave to interleave two row arrays of eq

ID: 3714970 • Letter: I

Question

Interleave Write a function called interleave to interleave two row arrays of equal length Ex: For row arrays arrayOne and arrayTwo, the output row array is arrayThree = arrayOne(1), arrayTwo(1), arrayOne(2) ,arrayTwo(2), ...]. The function should work for rows of any length Hint Create a new array by concatinating arrayOne and arrayTwo, then flattening the array to finally end up with the desired row array. No internal functions are needed. Ex: Flattening a [1,2,3,4] gives [ 1; 3 ; 2; 4] Restrictions: For and while loops should not be used Ex arrayOne-[2, 4, 8]; arrayTwo [3, 9, 27]; produces arrayThree [2, 3, 4, 9, 8, 27] Your Function Save C Reset MATLAB Documentation 1 function[ arrayThreeinterleave arrayOne, arrayTwo) 2% Interleave two row arrays of equal length, 31% arrayone and arrayTwo , to create a row array arrayThree 4% that interleaves the entries in arrayone and arrayTwo such that 5 % arrayThree larrayone ( 1 ) , arrayTwo ( 1 ) , arrayone(2) ,arrayTwo 1(2), ] 61% 71% create a 2D array with arrayone in 1st row and arrayTwo in 2nd row 9% Flatten C1 and take transpose arrayTh ree -....... % complete the code end Code to call your function C Reset arrayOne[2, 4, 8]; arrayTwo-[3, 9, 27]; Feedback?

Explanation / Answer

CREATE interleave.m AND PASTE BELOW CODE

function [arrayThree] = interleave(arrayOne,arrayTwo)
C1 = [arrayOne;arrayTwo]; %arrange arrays in two rows
arrayThree = C1(:); %convert it to column
end

CREATE test.m AND PASTE BELOW CODE

OR

YOU CAN TEST CODE FROM COMMAND LINE ALSO

arrayOne = [2,4,8];
arrayTwo = [3,9,27];
[arrayThree] = interleave(arrayOne,arrayTwo)

PLEASE REFER BELOW OUTPUT

arrayThree =
2
3
4
9
8
27
>>

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote