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!