THIS IS AN ADVANCE PROBLEM, ATTEMPT ONLY AFTER COMPLETING THE PREVIOUS PROBLEM M
ID: 3591275 • Letter: T
Question
THIS IS AN ADVANCE PROBLEM, ATTEMPT ONLY AFTER COMPLETING THE PREVIOUS PROBLEM Modify the function interleave, written in previously assignment, to create a function interleaveMod to interleave two row arrays named A2 and B2 of different lengths, 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. Hint: Use the internal functions length and min, and array indexing. Restrictions: You may not use a for or a while loop. For example >> A2 [1, 2, 3, 4, 5, 6] B2 [18, 20, 301, C3- inter!eaveMod(A2,B2) , 4 B2 = 10 20 30 10 20 30 4 Your Function Save C Reset , MATLAB Documentation 1 function [ arrayThree ] = interleaveMod( arrayone , arrayTwo ) 2Explanation / Answer
Please the following MATLAB function to interleave the arrays even with different lengths:
function C = interleaveMod (A,B)
% Calculate length of 2 input arrays
lv1 = length(A)
lv2 = length(B)
%divide the larger array in 2 parts
if lv2 < lv1
X = A (1 : lv2)
remain= A(lv2 + 1 : end)
Y = B
else
Y = B (1 : lv1)
remain= B(lv1 + 1 : end)
X = A
end
%Interview the common length of the arrays
t=min(lv1,lv2)
tmp = zeros(1,t*2)
tmp(1:2:t*2) = X
tmp(2:2:t*2) = Y
% Concatinate the interleaved & remaining array
C = horzcat (tmp , remain)
end
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.