Azzera filtri
Azzera filtri

"index out of bounds" error

1 visualizzazione (ultimi 30 giorni)
siddhesh rane
siddhesh rane il 23 Mag 2013
Risposto: Tasneem il 13 Lug 2022
Why am I getting Index out of bound error with below mentioned code?
S = size(coordinates,1);
n = 0;
while(n<S)
o = 1;
while(o<10)
D = rand(3,1);
n = n+1;
X(n)= coordinates(n);
n = n+1;
Y(n)= coordinates(n);
n = n+1;
Z(n)= coordinates(n);
end
patch(X,Y,Z,D);
hold on;
end

Risposte (1)

Tasneem
Tasneem il 13 Lug 2022
It is my understanding that your code has two while loops. The inner while loop seems to be an infinite loop since you are not incrementing o anywhere in the code and you are also incrementing the value of n in the inner while loop which eventually exceeds the index range of coordinates and gives you the 'index out of bound' error.

Tag

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by