Index exceeds the number of array elements (6).
    조회 수: 3 (최근 30일)
  
       이전 댓글 표시
    
I get this error and do not solve the problem please inform me how to solve it.
related codes,
for i=1:6
tt(1)=0;
yol=sqrt((xr(i+1)-xr(i))^2+(yr(i+1)-yr(i))^2);
tt(i+1)=tt(i)+yol/Vr;
end
xrr=horzcat(tt',xr);
yrr=horzcat(tt',yr);
xr - yr values;
3 -	3
2.68060147430381 -	3.13671296448901
4.36591862294010- 	6.36978774648130
6.81142757321166-	7.19528445914528
7.75732360564317-	4.90764974391571
8-	5
thanks for helps.
댓글 수: 1
  Sriram Tadavarty
    
 2020년 5월 14일
				Hi Sinan,
At the loop 6, the code access xr(6+1) which is not present. Inorder to solve this, you can append zeros at the front of xr and yr. The other one, being looping from 1:5. The actual case depends on what you needed in the output.
Hope this helps.
Regards,
Sriram
답변 (1개)
  Ayush Goyal
    
 2020년 6월 19일
        From my understanding of the question you are facing index issue in your code. Since you are iterating your for loop from i=1 to i=6, so when i=6 the code is accessing xr(6+1) and yr(6+1) but the length of both  xr and vr vector is 6. You should iterate your for loop for i=1:5 or you can append zeros at the end of xr and yr. You can refer to the following link for how to append to array or vector: 
댓글 수: 0
참고 항목
카테고리
				Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!