How to Suppress a Function?

2 次查看(过去 30 天)
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 个评论
Rightia Rollmann
Rightia Rollmann 2017-2-26
I meat when you run the code below in the Editor, you get an error showing that there are not enough input arguments. That means that MATLAB executes the function. I want it not to be executed even if I run the function.
function y = average(x)
y = sum(x)/length(x);
end
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 个)

类别

Help CenterFile Exchange 中查找有关 Entering Commands 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by