在Octave中声明函数时未定义的参数 [英] Undefined argument when declaring function in Octave
本文介绍了在Octave中声明函数时未定义的参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
尝试定义自己的随机生成器函数时,我得到未定义的变量/参数.
I get undefined variable/argument when trying to define my own random generator function.
代码:
function result = myrand(n, t, p, d)
a = 200 * t + p
big_rand = a * n
result = big_rand / 10**d
return;
endfunction
mrand = myrand(5379, 0, 91, 4)
错误:
>> myrand
error: 't' undefined near line 2 column 15
error: called from
myrand at line 2 column 7
推荐答案
您不能使用 function 关键字启动脚本. https://www.gnu.org/software/octave /doc/v4.0.1/Script-Files.html
You can't start a script with a function keyword. https://www.gnu.org/software/octave/doc/v4.0.1/Script-Files.html
这有效:
disp("Running...")
function result = myrand(n, t, p, d)
a = 200 * t + p
big_rand = a * n
result = big_rand / 10**d
return;
endfunction
mrand = myrand(5379, 0, 91, 4)
您应该得到:
warning: function 'myrand' defined within script file 'myrand.m'
Running ...
a = 91
big_rand = 489489
result = 48.949
mrand = 48.949
这篇关于在Octave中声明函数时未定义的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文