MATLAB: Finding 4 closest values to a value in an array

findmatrix arraymatrix manipulationsort

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?

Best Answer

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