[英]Octave : Index exceeds matrix dimensions
I wrote the following function in a file named conditionals.m: 我在名为conditionals.m的文件中编写了以下函数:
function result = conditionals(category, feature)
result=5;
end
I call this function from Octave's command line: 我从Octave的命令行调用此函数:
v=conditionals(3,4)
I get the following error: 我收到以下错误:
error : A(I) : Index exceeds matrix dimension.
Whats wrong here? 这里有什么不对?
The error: 错误:
error : A(I) : Index exceeds matrix dimension. 错误:A(I):索引超出矩阵维度。
Indicates that octave thinks that conditionals
is a matrix, not a function. 表示八度音符认为conditionals
是矩阵,而不是函数。
Octave probably doesn't know that conditionals
is a function - and instead it's treating it as a matrix. Octave可能不知道conditionals
是一个函数 - 而是将它视为一个矩阵。
Have you checked to see if the function is in Octave's search path? 您是否检查过该功能是否在Octave的搜索路径中?
This works for me. 这适合我。
octave> function result = conditionals (category, feature)
> result = 5;
> endfunction
octave> v = conditionals (3, 4)
v = 5
The error suggests that you have a variable with the same name as the function. 该错误表明您有一个与该函数同名的变量。 Type whos
at the Octave prompt to see a list of defined variables. 在Octave提示符下键入whos
以查看已定义变量的列表。 If you see one named conditionals
, remove it with clear conditionals
如果您看到一个命名conditionals
,请使用clear conditionals
将其删除
Also, if conditionals is a conditionals.m
file, make sure it's on the function search path. 此外,如果conditionals是conditionals.m
文件,请确保它位于函数搜索路径上。 Run path
at the Octave prompt to see the function search path. 在Octave提示符下运行path
以查看功能搜索路径。 Run which conditionals
at the command prompt to see where the function is located. 在命令提示符which conditionals
运行which conditionals
以查看函数的位置。
It happened to me as well and it can happen on any command, regardless of the command name. 它也发生在我身上,它可以在任何命令上发生,无论命令名称如何。 When I run the PS1(">>");
当我运行PS1(">>");
to change the command prompt in Ovtave, I got the same error. 要更改Ovtave中的命令提示符,我得到了同样的错误。
octave-3.2.3.exe:9> PS1(">>"); octave-3.2.3.exe:9> PS1(“>>”);
error: A(I): Index exceeds matrix dimension. 错误:A(I):索引超出矩阵维度。
As others also mentioned, this error fires when there is a parameter with the same command name. 正如其他人也提到的,当存在具有相同命令名的参数时会触发此错误。 It happens when we mistakenly enter the command with wrong syntax and hence, octave run the command and produce a variable with your command name that overload the internal command. 当我们错误地输入错误语法的命令时会发生这种情况,因此,八度运行命令并生成一个带有命令名称的变量,该变量会使内部命令过载。
You can verify this status by who
command. 您可以通过who
命令验证此状态。 If you can see the same variable name as your command here, you have to remove it. 如果您在此处可以看到与命令相同的变量名称,则必须将其删除。 Use clear variable_name
to remove the variable. 使用clear variable_name
删除变量。
Here is my output for PS1 command. 这是我的PS1命令输出。
Hope it helps. 希望能帮助到你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.