Question: *MATLAB* Create a function findtarget that will return the index (location) of the first item in a 2D matrix that matches a target number. Use

*MATLAB* Create a function findtarget that will return the index (location) of*MATLAB*

Create a function findtarget that will return the index (location) of the first item in a 2D matrix that matches a target number. Use nested while loops or for loops with a return command. The function has two inputs, the matrix and the target number, and two outputs, the row and column of the of the first item in the matrix equal to the target. You can assume at least one item in the matrix will match the target. The function will be called like this [r, c]=findtarget (testmatrix, target) Example Test cases [r,c]=findtarget([20 13 7 2 5], 7) results in r=1,C=3 [r,c]=findtarget([20 13 2; 11 2 11], 11) results in r=2,c=1 Hints: first determine the size of the matrix [num_rows num_cols] = size(testmatrix); Use one loop to increment through the rows of the matrix and another loop inside of it to increment through the columns of each row. The return command can be used to exit the function when the target is found

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!