MATLAB: What does “Index exceeds the number of array elements (6).” mean

array

Hey everybody,
I have a problem concerning my recent work. I get the following error message:
I also attached the code if that helps.
I really have no idea what it is from and why it occures here… What can I do here to avoid the failure?
Thank you a lot in advance!!
Johnny

Best Answer

You are using allepunkte as a for loop iterator. From Line 197 to Line 222 and you basically index two variables namely inside and outside in if else condition. The code syntax is
for allepunkte 1:8
for huellkoerper 1:4
if First_Condition
inside(allepunkte) = true;
else
outside(allepunkte) = true;
end
end
end
Now the problem is you have not initialized the variable inside and outside which means that the maximum index they will get will be their size. So initialize them before for loop starts. This will resolve the index problem