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

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!