Function 在倍频程中声明函数时未定义参数

Function 在倍频程中声明函数时未定义参数,function,octave,Function,Octave,当我试图定义自己的随机生成器函数时,我得到了未定义的变量/参数 代码: 错误: >> myrand error: 't' undefined near line 2 column 15 error: called from myrand at line 2 column 7 不能用function关键字启动脚本。 这项工作: disp("Running...") function result = myrand(n, t, p, d) a = 200 * t + p

当我试图定义自己的随机生成器函数时,我得到了未定义的变量/参数

代码:

错误:

>> myrand
error: 't' undefined near line 2 column 15
error: called from
myrand at line 2 column 7

不能用function关键字启动脚本。

这项工作:

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  
这是我的函数,在多次尝试之后,我注意到函数没有用参数调用,所以终端一直抛出一个未定义的错误

例如

函数的调用方式是“唤醒”,而不是这样 “醒来(“起来,发光!”)


你的代码在八度音阶下对我有效。您是否在命令行上执行它?如果它是脚本的一部分(例如foo.m),请确保第一行不以函数声明开头。常用的方法是添加
1开始时除了错误之外,这不是真正的
随机
,甚至不是
伪随机
,因为你的“随机”数只是
(200*t*n+p*n)/(10*d)
,这是一个简单的四个变量的一对一函数。你是否将其保存为
myrand.m
,然后调用
mrand=myrand(5379,0,91,4)
,还是在命令行中同时执行函数声明和函数调用?(在这种情况下,MATLAB会抛出一个错误“函数声明在此环境中不允许”,不确定倍频程)@Adrian是的,倍频程允许内嵌函数定义,而MATLAB不允许。(虽然听起来好像2016b会)谢谢,但你知道为什么它会这样吗!??
warning: function 'myrand' defined within script file 'myrand.m'   
Running ...  
a =  91  
big_rand =  489489  
result =  48.949  
mrand =  48.949  
function wakeup(message)
  printf("\a%s\n",message)
endfunction 


wakeup("Rise and shine!");