MATLAB function 'nearest' does not work.

11 visualizzazioni (ultimi 30 giorni)
Tim Klaproth
Tim Klaproth il 13 Giu 2022
Commentato: Steven Lord il 13 Giu 2022
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 Commento
Stephen23
Stephen23 il 13 Giu 2022
Modificato: Stephen23 il 13 Giu 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:

Accedi per commentare.

Risposte (2)

Steven Lord
Steven Lord il 13 Giu 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 Commenti
Stephen23
Stephen23 il 13 Giu 2022
which nearest -all
/MATLAB/toolbox/fixedpoint/fixedpoint/nearest.m /MATLAB/toolbox/matlab/graphfun/@digraph/nearest.m % Shadowed digraph method /MATLAB/toolbox/matlab/graphfun/@graph/nearest.m % Shadowed graph method
nearest(1.2)
ans = 1
Steven Lord
Steven Lord il 13 Giu 2022
Huh. That suggests the documentation may need to be updated. I'll note that to the documentation staff for Fixed-Point Designer.

Accedi per commentare.


Star Strider
Star Strider il 13 Giu 2022
The nearest function is used with graph or digraph objects. Apparently, you are using it with something else.
Without knowing anything at all about what you are using it with, the inpolygon, pdist, pdist2, or knnsearch functions could be appropriate.
  1 Commento
Star Strider
Star Strider il 13 Giu 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.

Accedi per commentare.

Tag

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by