Question: Matlab code please Fun with find Write a function to return the value and index of a number in a vector / matrix that is
Matlab code please
Fun with find Write a function to return the value and index of a number in a vector / matrix that is closest to a desired value. The function should be called as [val, ind = findClosest(x, desiredValue). This function can be accomplished in less than five lines. You will find abs, min and/or find useful, Hint: You may have some trouble using min when x is a matrix. To convert the matrix to a vector, you can use y = x(:). Show that it works by finding the value closest to 3/2 (and index of said value) in sin( linspace(0,5,100) ) + 1
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
