User defined function "not enough inputs"

10 visualizaciones (últimos 30 días)
Seoyoung Cho
Seoyoung Cho el 20 de Feb. de 2020
Editada: Seoyoung Cho el 21 de Feb. de 2020
I wrote a code with user-defined function on top of the code and other codes using the user-defined function at the bottom.
However, it is not working when I run the program saying, "Not enough input arguments."
And gives me error message on the line that I have the calculation for the function.
Is there any problem with my code?

Respuesta aceptada

Jon
Jon el 20 de Feb. de 2020
The error message means that when you called the function, either on the command line, or in another script, you did not provide it with the three arguments it requires. Make sure that when you call the function your call looks something like
z = ht(h,v,t); % name of the variables doesn't matter but there have to be three input variables
  6 comentarios
Stephen23
Stephen23 el 20 de Feb. de 2020
@Seoyoung Cho: call the function:
  1. from the command line by typing it out exactly as Jon's answer shows and then pressing ENTER on your keyboard.
  2. inside a script/function/class/... and then running that script/function/class/...
Jon
Jon el 20 de Feb. de 2020
Editada: Jon el 20 de Feb. de 2020
So I think I understand your confustion. You can run a script, (a collection of MATLAB commands) directly from the editor, by pressing the green run button. This is equivalent to having typed all of the commands that are in the script on the command line.
You can not run a function directly from the editor with the green run button, because the function needs some input arguments. In your case it needs three input arguments a height, velocity and time, and it wouldn't know where to get those inputs if you try to run it directly from the editor.
You could write another script (where the first line is not function ...) that assigns the height, velocity, and time variables, and then calls your function ht and run that script directly from the editor using the green run button.
Hope this helps

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Entering Commands en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by