User defined function "not enough inputs"

10 ビュー (過去 30 日間)
Seoyoung Cho
Seoyoung Cho 2020 年 2 月 20 日
編集済み: Seoyoung Cho 2020 年 2 月 21 日
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?

採用された回答

Jon
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
Stephen23 2020 年 2 月 20 日
@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 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 件)

カテゴリ

Help Center および File ExchangeEntering Commands についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by