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?

 Akzeptierte Antwort

Jon
Jon am 20 Feb. 2020

0 Stimmen

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 Kommentare

Adam
Adam am 20 Feb. 2020
And don't just press the big green 'Run' button!
Seoyoung Cho
Seoyoung Cho am 20 Feb. 2020
I have multiple input variables in initialization tho
Jon
Jon am 20 Feb. 2020
Did you find the error? If not please post the exact code, or command line where you call the function. I think you will see that you have less than 3 arguments in that call, but if not, maybe another set of eyes could help
Stephen23
Stephen23 am 20 Feb. 2020
Seoyoung Cho's "flag" to Adam's comment moved here:
Then how can I run the whole program?
Stephen23
Stephen23 am 20 Feb. 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 am 20 Feb. 2020
Bearbeitet: Jon am 20 Feb. 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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Debugging and Analysis finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 20 Feb. 2020

Bearbeitet:

am 21 Feb. 2020

Community Treasure Hunt

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

Start Hunting!

Translated by