"index out of bounds" error

1 次查看(过去 30 天)
siddhesh rane
siddhesh rane 2013-5-23
回答: Tasneem 2022-7-13
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

回答(1 个)

Tasneem
Tasneem 2022-7-13
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.

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by