[英]Error:Index exceeds matrix dimensions
I made this script: 我做了这个脚本:
disp('Answer>>There are 25 prime numbers exist between 1-100')
x=isprime(1:100);
sum(x)
And from some reason it runs just once. 由于某种原因,它只运行一次。 For example, this script has the file name "question4" so when I type it in the main command it prints: "There are.... ans=25" - which is perfect!
例如,此脚本的文件名为“ question4”,因此当我在主命令中键入该脚本时,它会打印:“ There .. ans = 25”-完美! but when I type again "question4" I get this error:
但是当我再次输入“ question4”时,出现此错误:
Index exceeds matrix dimensions.
Error in question4 (line 3)
sum(x)
Any reason why?? 有什么原因吗? Thanks in advanced!
提前致谢!
Be careful not to use sum
or any other built-in function name as a variable. 注意不要将
sum
或任何其他内置函数名称用作变量。 To see if you are using it as a variable, check with the following: 要查看是否将其用作变量,请检查以下内容:
>> which sum
sum is a variable.
If your output looks like the above, the variable sum
is preventing the built-in sum
function from being called as intended. 如果您的输出如上所示,则变量
sum
将阻止按预期方式调用内置sum
函数。 Try clear sum
and make sure you are not assigning sum
anywhere in your script. 尝试
clear sum
,并确保没有在脚本中的任何地方分配sum
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.