Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a function named \"location_of_target\" that takes as its arguments the fo

ID: 3080250 • Letter: W

Question

Write a function named "location_of_target" that takes as its arguments the following: An array of integer values; An integer "target value". The function should determine whether the given target value occurs in any of the cells of the array, and if it does, the function should return the subscript of the cell containing the target value. If more than one of the cells contains the target value, then the function should return the largest subscript of the cells that contain the target value. If the target value does not occur in any of the cells, then the function should return the sentinel value -1. Thus, for example, if the target value that's passed to the function is 34 and the array that's passed to the function looks like this: Then the target value occurs in cells 3 and 5, so the function should return the integer value 5

Explanation / Answer

function z = location_of_target(x, n) % x - array of values % n = target value z = find(x==n); % find all values z = max(z) - 1; % return just the biggest and reorder so that the list starts at zero

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote