我是matlab的新手,我正在尝试定义一个相当复杂的函数来绘制它。文件内容如下:
function [res] = distribution (input)
a = factorial(30)
b = factorial(input) * factorial(30-input)
c = power(0.05, input)
d = power(0.95, 30-input)
a/b*c*d
end
在名为distribution的文件中,扩展名为.m。但是当我运行它时,错误返回:"使用分发时出错(第4行)。没有足够的输入参数。"
我通读了#34;入门"并找不到解决方案。有没有人对此提出建议?
答案 0 :(得分:3)
函数distribution(..)
的单个参数的名称,即参数input
,与Matlab的the existing native input
command冲突,
input
:提示用户输入。...
x = input(prompt)
尝试选择此参数的其他名称(在下面的示例中为foo
),并且还要记住通过将结果分配给返回变量res
来返回结果:
function res = distribution (foo)
a = factorial(30);
b = factorial(foo) * factorial(30-foo);
c = power(0.05, foo);
d = power(0.95, 30-foo);
res = a/b*c*d; % <--- note, return parameter assignment
end