Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Given a circular row array A and integer value n, shift A by n positions to the right. Problem Given a 'circular' row array A
Given a circular row array A and integer value n, shift A by n positions to the right.
Problem Given a 'circular' row array A and an interger value n, shift A by n positions to the right. This is similar to shift array problems on zyBook (we've seen two) with three twists: 1. We are shifting the array to the right instead of left. 2. We are shifting the array by a variable number of positions. 3. The array is circular so the left-most elements are no longer lost. Instead, they are 'shifted to the right side of the array. Consider the 1x9 row array [1, 2, 3, 4, 5, 6, 7, 8, 9]. For various values of n, the expected outputs are: . n = 1: [9, 1, 2, 3, 4, 5, 6, 7, 8] n = 2: [8, 9, 1, 2, 3, 4, 5, 6, 7] . n = 3: [7, 8, 9, 1, 2, 3, 4, 5, 6] n = 8: [2, 3, 4, 5, 6, 7, 8, 9, 1] n = 9:[1, 2, 3, 4, 5, 6, 7, 8, 9] . n = 10: [9, 1, 2, 3, 4, 5, 6, 7, 8] Notice that when n is equal to or larger than the length of the array, the result is the same as Notice that when n is equal to or larger than the length of the array, the result is the same as (n mod array's length). Task Write a function circular ShiftRight that takes two inputs (array and shift value, in this order) and returns a shifted array as its output. Hint To receive full credit, you will need to use the remainder function (mod) and end keyword to manipulate the input array. The length of the array can be found using length function. The use of circshift function is strictly prohibited. Function E Save Reset DI MATLAB Documentation 1 % Modify the function header below 2 function CHANGE_THIS_HEADER 3 % YOUR CODE STARTS 4 5 % YOUR CODE ENDS 6 end Code to call your function C Reset 1 inputArr = [1:9]; 2 circularShiftRight(inputArr, 1) 3 circularShiftRight(inputArr, 2) 4 circularShiftRight(inputArr, 9) 5 circularShiftRight(inputArr, 10) Run Function Assessment: Submit Check whether circshift is used Assessment: Submit Check whether circshift is used Check the function definition Check if circularShiftRight correctly shifts 1x9 array by 1 position. Check if circularShiftRight correctly shifts variable-sized array by 1 position. Right correctly shifts 1x9 array a variable number of Check if circula position. Check if circularShiftRight correctly shifts variable-sized array by a variable number of positionStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started