Finding 4 closest values to a value in an array

20 次查看(过去 30 天)
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
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 个)

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by