User defined function "not enough inputs"
6 次查看(过去 30 天)
显示 更早的评论
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?
0 个评论
采纳的回答
Jon
2020-2-20
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 个评论
Stephen23
2020-2-20
- from the command line by typing it out exactly as Jon's answer shows and then pressing ENTER on your keyboard.
- inside a script/function/class/... and then running that script/function/class/...
Jon
2020-2-20
编辑:Jon
2020-2-20
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
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!