Given a row vector of numbers, find the indices of the two nearest numbers.
Examples:
[index1 index2] = nearestNumbers([2 5 3 10 0 -3.1])
index1 = 1 index2 = 3
[index1 index2] = nearestNumbers([-40 14 22 17])
index1 = 2 index2 = 4
Notes
1684 Solvers
Getting the absolute index from a matrix
169 Solvers
224 Solvers
237 Solvers
390 Solvers
MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi
Learn moreOpportunities for recent engineering grads.
Apply Today