Problem 29. Nearest Numbers
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
- The indices should be returned in order such that index2 > index1.
- There will always be a unique solution.
Solution Stats
Problem Comments
-
4 Comments
Show
1 older comment
Jon
on 4 Dec 2013
Best score without using Neural Net Toolbox is 38
Droopy Cee
on 13 Mar 2017
123 lol.
Jiahang Li
on 2 Feb 2018
It took me half an hour to solve test 4.
Ibrahim Wajid
on 22 Jun 2022
pretty simple
Solution Comments
Show commentsProblem Recent Solvers4549
Suggested Problems
-
Reverse the Words (not letters) of a String
440 Solvers
-
Back to basics 4 - Search Path
367 Solvers
-
Back to basics 23 - Triangular matrix
1001 Solvers
-
"Low : High - Low : High - Turn around " -- Create a subindices vector
540 Solvers
-
Create a vector whose elements depend on the previous element
680 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!