Effacer les filtres
Effacer les filtres

Error ' Index in position 2 exceeds array bounds'.how to correct this.

3 vues (au cours des 30 derniers jours)
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?

Réponse acceptée

Geoff Hayes
Geoff Hayes le 6 Avr 2022
Modifié(e) : Geoff Hayes le 6 Avr 2022
@susan sara - in your while loop conditions
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
. At the end of the loop you do
. 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))
for j=y(1):1:y(length(i))
for j=z(1):1:z(length(i))
Is the above correct? Is there a missing end for the first for loop?

Plus de réponses (0)


En savoir plus sur Matrix Indexing dans Help Center et File Exchange


Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by