Matlab Function : error

1 回表示 (過去 30 日間)
YOUNGJUN Park
YOUNGJUN Park 2020 年 9 月 27 日
コメント済み: Walter Roberson 2020 年 9 月 27 日
I want to run this function so I can test with any number
function[Young,TotalPerimeter] = YoungJay(Width, Area) %line 1
Young=(Area/Width)-0.25; %line3
TotalPerimeter= 2*((Area/Width)-0.25)+Width+sqrt(2)*Width;
end
error message on command window
Not enough input arguments.
Error in YoungJay (line 3)
Young=(Area/Width)-0.25;

採用された回答

Walter Roberson
Walter Roberson 2020 年 9 月 27 日
You cannot run that code just by pressing the green run button in the editor, and you cannot run that code just by invoking the function name. If you were to try to do either one of those, then MATLAB would not know what values to use for the input arguments Width and Area.
When you run a function, MATLAB never looks in your current workspace for variables with the same name as the input parameters. For example,
Width = 7
Y = YoungJay
then MATLAB will never see that function has an input named Width and so look in the calling environment to see if a Width exists there to use.
When you want a function to use a parameter, you need to pass in the parameter when you invoke the function. For example, either of
Width = 7
Area = 19
Y = YoungJay(Width, Area)
or
Y = YoungJay(7, 19)
  3 件のコメント
YOUNGJUN Park
YOUNGJUN Park 2020 年 9 月 27 日
I invoked the code , YoungJay(6,80) , yes it echoes some value but I don't understand what this value is; I expected two outputs 1. Young , 2. TotalPerimeter
Walter Roberson
Walter Roberson 2020 年 9 月 27 日
[Young, TotalPerimeter] = YoungJay(6,80)

サインインしてコメントする。

その他の回答 (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