필터 지우기
필터 지우기

How to chose the nearest value

조회 수: 2 (최근 30일)
Matt Learner
Matt Learner 2012년 2월 23일
편집: Mohammad Monfared 2013년 10월 21일
Suppose I have a point at location (3,800) and for this point, I have to select the nearest point. I have 3 points say (2,790), (3,770) and (2.5,780). How to find which one out of these three points is nearest to the given point (3,800)?

채택된 답변

nanren888
nanren888 2012년 2월 23일
So where are you stuck? Give us a hint of what you're thinking so far. Maybe calculate the distances & take the mimimum?
>> p=[3;800];
q = [2,790;3,770;2.5,780].';
d = sum((p*ones([1,size(q,2)])-q).^2,1);
[~,minI] = min(d)
minI =
1
  댓글 수: 1
Jan
Jan 2012년 2월 23일
Solving homework questions is no benefit for the author or the forum.
REPMAT or BSXFUN are smarter than a multiplication with ONES.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by