Question: TO 11. Create a function findtarget that will return the indices (locations) of ALL items in a 2D array that match a target number. Use
TO 11. Create a function findtarget that will return the indices (locations) of ALL items in a 2D array that match a target number. Use nested while 42 loops or for loops. The function has two inputs, the matrix and the target number, and one output, an array containing the indices (row and column #) of all occurences of the target number. Each instance of the target should have the indices recorded in a new row. You can assume at least one item in the matrix will match the target. The function will be called like this result-findtarget(testmatrix, target) Example Test case findtarget([20 13 2; 11 2 11), 11) results in 2,1,2,3] Hint: 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. Use another variable to count the number of occurences. Increment the row number of your result matrix (the count of the number of occurences) after each occurence is found. function findtarget to find target number in matrix function fr.c] - findtarget(testatrix, taneet) X finding the row and colum size [numrows, nos cols] - size(testatrix): nested for loop each for a row and column for 1 - 1 num_rows for 1 cols * If target number matches with satrix number % return and if(testatrici]) = target) C-3: return; end lend end end
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
