フィルターのクリア

Index exceeds the number of array elements (6).

1 回表示 (過去 30 日間)
Sinan Yigit
Sinan Yigit 2020 年 5 月 14 日
回答済み: Ayush Goyal 2020 年 6 月 19 日
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
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
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:

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by