Help with 'find' function

1 visualización (últimos 30 días)
aurc89
aurc89 el 25 de Feb. de 2014
Comentada: aurc89 el 26 de Feb. de 2014
Hello! I have a vector X with some elements, and I want to find the position p of the element of X whose value is as close as possible to a known value A. For example, X = [1, 4.5, 6, 3 ,2.8] and A=4.7. The position of the element in X whose value is as close as possible to A is p=2, since X(2)=4.5 . Is there a fast way to do this, maybe using the function 'find' ? Thank you very much

Respuesta aceptada

Paul
Paul el 25 de Feb. de 2014
[val,ind]=min(abs(X-A))
Where val is the distance and ind the index .

Más respuestas (0)

Categorías

Más información sobre Matrices and Arrays en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by