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?

 Respuesta aceptada

Sindar
Sindar el 28 de Sept. de 2020
use mink
[~,idx] = mink(abs(data-find_point),5);
data(idx)

2 comentarios

AAS
AAS el 29 de Sept. de 2020
Hi, Thankyou! How can I extend this to select maybe two values above and below the value I want?
Sindar
Sindar el 29 de Sept. de 2020
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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Preguntada:

AAS
el 28 de Sept. de 2020

Comentada:

el 29 de Sept. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by