"index out of bounds" error

1 view (last 30 days)
siddhesh rane
siddhesh rane on 23 May 2013
Answered: Tasneem on 13 Jul 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

Answers (1)

Tasneem
Tasneem on 13 Jul 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.

Tags

Products

Community Treasure Hunt

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

Start Hunting!