Error ' Index in position 2 exceeds array bounds'.how to correct this.
1 次查看(过去 30 天)
显示 更早的评论
When run it, shows
"Index in position 2 exceeds array bounds. Index
must not exceed 2.
Error in practice (line 20)
while(abs(a(k)-a(k-1))>=0.01) && abs(b(k)-b(k-1))>=0.01 && rms(abs(A(:,k)-A(:,k-1)))>=0.01"
Please help to correct this?
0 个评论
采纳的回答
Geoff Hayes
2022-4-6
编辑:Geoff Hayes
2022-4-6
while(abs(a(k)-a(k-1))>=0.01) && abs(b(k)-b(k-1))>=0.01 && rms(abs(A(:,k)-A(:,k-1)))>=0.01
you have
rms(abs(A(:,k)-A(:,k-1)))
. At the end of the loop you do
k=k+1;
. I don't see anywhere in the code where you update A for k+1 and so I suspect the error message is originating when indexing into A on the second iteration of the loop when k is 3. You may want to review this code
for j=x(1):1:x(length(i))
A(j,k)=((H(j))/(a(k)))-1
for j=y(1):1:y(length(i))
A(j,k)=((H(j))/(b(k)))-1
end
for j=z(1):1:z(length(i))
A(j,k)=G(j)
end
Is the above correct? Is there a missing end for the first for loop?
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!