Need help with this Matlab script question? For loop!!
显示 更早的评论
I keep getting this error 'Attempted to access x(3); index out of bounds because numel(x)=2.' It's really frustrating!!!
采纳的回答
更多回答(1 个)
Robert Cumming
2014-7-29
编辑:Robert Cumming
2014-7-29
It the start of your while loop the condition includes a check on x(3), hence why you get the error.
edit: you could fix it this way:
while true
x(k) = x(k-1) + x(k-2);
k = k+1;
if (abs(x(k)./x(k-1) - x(k-1)./x(k-2))>0.001)
break
end
end
类别
在 帮助中心 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!