Fixed bug by changing i=length(planC{indexS.structures}(structNum).contour) to i=1:length(planC{indexS.structures}(structNum).contour)