Answer to Question #99178 in MatLAB for lana majeed

Question #99178
Fun with find. Write a function to return the index of the value that is nearest to a desired
value. The function declaration should be: ind=findNearest(x, desiredVal). x is a
vector or matrix of values, and desiredVal is the scalar value you want to find. Do not
assume that desiredVal exists in x, rather find the value that is closest to desiredVal. If
multiple values (entries) have the same distance from desiredVal, return all of their indices.
Test your function to make sure it works on a few vectors and matrices. Useful functions are
abs, min, and find. Hint: You may have some trouble using min when x is a matrix. To convert a
matrix Q into a vector you can do something like y=Q(:). Then, doing m=min(y) will give
you the minimum value in Q. To find where this minimum occurs in Q, do ind=find(Q==m);
1
Expert's answer
2019-11-22T03:24:38-0500
Dear lana majeed, your question requires a lot of work, which neither of our experts is ready to perform for free. We advise you to convert it to a fully qualified order and we will try to help you. Please click the link below to proceed: Submit order

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS