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 ExchangeResizing and Reshaping 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