nearest(100*rand()) does not work
Afficher commentaires plus anciens
My professor wants us to utilize nearest(100*rand()) when she types this code out it works but when I utilize it I get a "Check for incorrect argument data type or missing argument in call to function 'nearest'." Why does it work for her but not me?
7 commentaires
James Tursa
le 2 Fév 2022
According to the doc the input needs to be an fi data type, not a double data type. Can you use round( ) or fix( ) instead?
What are the results of the following check?
which nearest -all
I'm assuming that the fixedpoint toolbox version is the one that you're after. If you don't have the FPT, or if you have some other function called which.m, you'll need to straighten that out.
In the case that you don't have FPT, you can always roll your own any number of ways.
a = [-100 100]*rand()
b = floor(a+0.5)
@James Tursa It seems to work fine for me in R2016b and here as well
nearest(a)
At least in the version I have, the version of nearest.m in the FPT gives no indication that it only supports fi objects.
Robert Green
le 2 Fév 2022
DGM
le 2 Fév 2022
Start with the 'which' command I gave. Run that in the command window. What does it return?
If you're getting other errors, show exactly what the code was and the full text of the error message.
Robert Green
le 2 Fév 2022
"When I copy and paste those into my live script it doesn't do anything. I'll attach a picture."
Do not copy and paste those lines. Those lines are the output printed in the command window, which DGM showed you as examples of what to expect. Trying to run those lines will not produce anything but error messages.
The line which DGM showed you and asked you to run is this one:
which nearest -all
Paste that into the command window and press enter. Show us the output.
Robert Green
le 2 Fév 2022
Réponse acceptée
Plus de réponses (1)
If you're just trying to generate a random integer from 0 to 100,
randi([0,100])
Catégories
En savoir plus sur Argument Definitions dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!