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 =
4Notes
- The indices should be returned in order such that index2 > index1.
- There will always be a unique solution.
Solution Stats
Problem Comments
4 Comments
Solution Comments
Show comments
Loading...
Problem Recent Solvers5120
Suggested Problems
-
Select every other element of a vector
36863 Solvers
-
Generate a vector like 1,2,2,3,3,3,4,4,4,4
14116 Solvers
-
Right Triangle Side Lengths (Inspired by Project Euler Problem 39)
2117 Solvers
-
Find the sides of an isosceles triangle when given its area and height from its base to apex
2211 Solvers
-
1761 Solvers
More from this Author96
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
Best score without using Neural Net Toolbox is 38
123 lol.
It took me half an hour to solve test 4.
pretty simple