
MATLAB function 'nearest' does not work.
11 views (last 30 days)
Show older comments
Hello,
when I call the function "nearest()" I obtain the error message: "Check for incorrect argument data type or missing argument in call to function 'nearest'." I am using R2021b.
The following toolboxes are installed:
- MATLAB Version 9.11 (R2021b)
- Aerospace Toolbox Version 4.1 (R2021b)
- Deep Learning Toolbox Version 14.3 (R2021b)
- Financial Toolbox Version 6.2 (R2021b)
- Image Processing Toolbox Version 11.4 (R2021b)
- MATLAB Report Generator Version 5.11 (R2021b)
- Mapping Toolbox Version 5.2 (R2021b)
- Optimization Toolbox Version 9.2 (R2021b)
- Parallel Computing Toolbox Version 7.5 (R2021b)
- Statistics and Machine Learning Toolbox Version 12.2 (R2021b)
The MATLAB documentation for "nearest()" (https://de.mathworks.com/help/fixedpoint/ref/nearest.html) does not say anything about required toolboxes though.
Why does MATLAB not execute tht function "nearest()" correctly?
Thanks for your help.
1 Comment
Stephen23
on 13 Jun 2022
Edited: Stephen23
on 13 Jun 2022
"The MATLAB documentation for "nearest()" (https://de.mathworks.com/help/fixedpoint/ref/nearest.html) does not say anything about required toolboxes though."
You can always identify the toolbox from both the URL and from the contents browser hierarchy:

Answers (2)
Steven Lord
on 13 Jun 2022
I find two functions named nearest in MathWorks products when I search the documentation.
One is the nearest method for graph and digraph objects, which is part of MATLAB. As stated on that page, the first input argument G must be a "graph object | digraph object". If it isn't, you cannot successfully call this method. [You could call the method if one of the later inputs was a graph or digraph object, but if that first input isn't one the method will error out.]
One is the nearest method for fi objects, which is part of Fixed-Point Designer. The one input to this method must be a "Input fi array, specified as scalar, vector, matrix, or multidimensional array." If you try to call this with a normal double precision array as input, it will not work: MATLAB will not call this method.
Which of these methods were you hoping to call and what data did you pass into your nearest() call? Or were you hoping to do something else and hoped that a function named nearest() would let you achieve your goal?
4 Comments
Steven Lord
on 13 Jun 2022
Huh. That suggests the documentation may need to be updated. I'll note that to the documentation staff for Fixed-Point Designer.
Star Strider
on 13 Jun 2022
1 Comment
Star Strider
on 13 Jun 2022
I didn’t see Fixed-Point Designer Toolbox in the list in the original post (and I still don’t see it there), so I didn’t link to functions in it.
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!