Question: Problem 3 . 3 Array Manipulation. You are tasked with creating a MATLAB function that performs specific manipulations on an input array and produces an

Problem 3.3
Array Manipulation. You are tasked with creating a MATLAB function that performs specific manipulations
on an input array and produces an output array. Your function should take an array of integers as input and
return an array that meets certain conditions. Follow the instructions below to create the function:
1.' Function Signature:
function outputArray = manipulateArray(inputArray)
Input:
The inputArray is a 1-dimensional array of integers with a length of )N(1000. The array elements
are guaranteed to be within the range of -100 to 100(inclusive).
Output:
The function should return an outputArray which is also a 1-dimensional array of integers with the same length
as the inputArray.
Manipulation Conditions:
Your function needs to implement the following manipulations on the inputArray to create the outputArray:
a) Double the values of even-indexed elements in the inputArray.
b) Square the values of odd-indexed elements in the inputArray.
c) Leave prime-numbered indices unchanged in the outputArray.
d) Replace negative values in the inputArray with their absolute values in the outputArray.
Example:
If the inputArray is: 3,-2,5,10,-7
The outputArray should be: 9,4,25,20,7
Write a script to test your manipulateArray function using various input arrays. Ensure that the function
works correctly for different input cases and meets the specified conditions.
Include comments in your code to explain each step of your solution.
Remember to handle corner cases and edge scenarios gracefully.
Your task is to implement the manipulateArray function according to the given specifications and write the
testing script to verify its correctness.
Problem 3 . 3 Array Manipulation. You are tasked

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 Programming Questions!