Help with 'find' function

조회 수: 1 (최근 30일)
aurc89
aurc89 2014년 2월 25일
댓글: aurc89 2014년 2월 26일
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

채택된 답변

Paul
Paul 2014년 2월 25일
[val,ind]=min(abs(X-A))
Where val is the distance and ind the index .
  댓글 수: 1
aurc89
aurc89 2014년 2월 26일
Thnaks Paul!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by