"index out of bounds" error
1 view (last 30 days)
Show older comments
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
0 Comments
Answers (1)
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.
0 Comments
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!