Question: Write a MATLAB function: [y] = swap(x, L), that will swap the last L entries in vector x with the first L entries of the
Write a MATLAB function: [y] = swap(x, L), that will swap the last L entries in vector x with the first L entries of the same vector and call the new vector: y. Preserve the original vector x. Assume that your vector is of even length. Example: L = 2 x = [5 3 2 1 4 5] y = [4 5 2 1 5 3] L = 3 x = [5 3 2 1 4 5] y = [l 4 5 5 3 2] L = 0 x = [5 3 2 1 4 5] y = [5 3 2 1 4 5] An error message should be issued if x has odd length or if L is larger than half the length of x. To improve your grade try to use vectorized code as much as you find possible. Insert code in the next page
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
