Write function to search contents of array for elements


Write a function that accepts an array a as input, and searches the contents of the array for elements in three different ranges: [0 - 10), [10 - 50) and [50 - 100]. The function builds three arrays that contain the elements from the a array that are in found in each range. These 3 arrays are the output arguments. For an input of a=[2 5 36 70 40 62 8],your program should return these three arrays

x = [2 5 8]

y = [36 40]

z = [70 62]

If the input has no elements in a specific range, the corresponding output array should be empty. If any element in a is greater than 100 or is negative, the program should display the element and the index where it is found using fprintf , and then use the error function to terminate the program. Make sure your program prints all the invalid elementsin the format shown before terminating it using error.

For example for an input of a=[2 5 36 70 40 102 8],your program should return,

The array has an invalid element 102 at index 6.

Request for Solution File

Ask an Expert for Answer!!
Mechanical Engineering: Write function to search contents of array for elements
Reference No:- TGS0733895

Expected delivery within 24 Hours