Octave 说变量是未定义的,即使它们是
Octave says variables are undefined even when they are
我有以下代码
function W = robust(a,c,y)
W = pinv(a' * c * a) * a' * c *y;
endfunction
但是,当我尝试 运行 时,出现以下错误。
error: 'a' undefined near line 4 column 12
error: called from
robust at line 4 column 5
这完全没有意义。我在这里做错了什么?
编辑:我通过 emacs 调用它。所以,我正在使用命令 'octave-source-file',它在次级八度过程中执行文件。我发现如果这个缓冲区不是我开始该过程的地方,它就可以工作。如果我在另一个文件上启动八度音程进程,然后将此文件发送到下级进程,它会计算函数。
Octave从MATLAB继承了一个"function files"的概念,不同于"script files"。假定 "function file" 包含一个需要在文件执行时 调用 的函数。所以当你想到 "I'm defining it" 时,Octave 认为你正在调用那个函数。由于您没有提供任何输入,因此存在 "undefined variable" 错误。
Once Octave finds a file with a name that matches, the contents of the file are read. If it defines a single function, it is compiled and executed.
Unlike a function file, a script file must not begin with the keyword function. If it does, Octave will assume that it is a function file, and that it defines a single function that should be evaluated as soon as it is defined.
我有以下代码
function W = robust(a,c,y)
W = pinv(a' * c * a) * a' * c *y;
endfunction
但是,当我尝试 运行 时,出现以下错误。
error: 'a' undefined near line 4 column 12
error: called from
robust at line 4 column 5
这完全没有意义。我在这里做错了什么?
编辑:我通过 emacs 调用它。所以,我正在使用命令 'octave-source-file',它在次级八度过程中执行文件。我发现如果这个缓冲区不是我开始该过程的地方,它就可以工作。如果我在另一个文件上启动八度音程进程,然后将此文件发送到下级进程,它会计算函数。
Octave从MATLAB继承了一个"function files"的概念,不同于"script files"。假定 "function file" 包含一个需要在文件执行时 调用 的函数。所以当你想到 "I'm defining it" 时,Octave 认为你正在调用那个函数。由于您没有提供任何输入,因此存在 "undefined variable" 错误。
Once Octave finds a file with a name that matches, the contents of the file are read. If it defines a single function, it is compiled and executed.
Unlike a function file, a script file must not begin with the keyword function. If it does, Octave will assume that it is a function file, and that it defines a single function that should be evaluated as soon as it is defined.