How to Suppress a Function?

3 ビュー (過去 30 日間)
Rightia Rollmann
Rightia Rollmann 2017 年 2 月 26 日
コメント済み: Jan 2017 年 2 月 26 日
When I run the code below, MATLAB runs it and I get the error “Not enough input arguments”. Isn’t there any way to tell MATLAB to wait to call the function until I execute, for example, average(5)?
function y = average(x)
y = sum(x)/length(x);
end

採用された回答

Jan
Jan 2017 年 2 月 26 日
The question is not clear. Calling the shown code does not cause an error:
average(5)
runs fine. It would only fail, if it is called without inputs. Please post the complete error message to reveal the actual problem. Explain, which action causes the error.
  2 件のコメント
Jan
Jan 2017 年 2 月 26 日
You run this code in the editor using the green arrow or F5? Then the input is missing. Running means executing the code. This is the same. So running without executing is not meaningful.
Save this function as "average.m" file. Then you can run it from other codes or from the command window.

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

その他の回答 (0 件)

カテゴリ

Find more on Workspace Variables and MAT-Files in Help Center and File Exchange

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by