Finding 4 closest values to a value in an array

How do I find multiple points close to a particular number in an array? I can do this for one value but how do I extend that?

 채택된 답변

Sindar
Sindar 2020년 9월 28일

1 개 추천

use mink
[~,idx] = mink(abs(data-find_point),5);
data(idx)

댓글 수: 2

AAS
AAS 2020년 9월 29일
Hi, Thankyou! How can I extend this to select maybe two values above and below the value I want?
Sindar
Sindar 2020년 9월 29일
You'd play around with (data-find_point) without the abs(). Algorithm something like:
  • separate data into values equal to, larger than, smaller than find_point
  • keep all equal to
  • find smallest 2 positive error
  • find largest 2 negative error

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

질문:

AAS
2020년 9월 28일

댓글:

2020년 9월 29일

Community Treasure Hunt

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

Start Hunting!

Translated by