"index exceeds matrix dimensions"

I can't figure out why it is showing me this, here are the lines of relevant code, thanks for any help you might have

 採用された回答

Birdman
Birdman 2017 年 12 月 12 日
編集済み: Birdman 2017 年 12 月 12 日

0 投票

The length of x vector is 3 and you defined y vector the same vay but at the line 21 when i=4, you try to reach y(4), which is invalid because you already defined that y has 3 elements at the line 11. Check it.

2 件のコメント

Mia Rocco
Mia Rocco 2017 年 12 月 12 日
ok, so I changed it to y=zeros(1,3), but I'm getting the same message, if I defined the index as i=1:3, shouldn't it stop at y(3)?
Birdman
Birdman 2017 年 12 月 12 日
No, but at line 21, you still try to reach i+1, which makes 4 when i=3. The error arises from there.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMatrix Indexing についてさらに検索

質問済み:

2017 年 12 月 12 日

コメント済み:

2017 年 12 月 12 日

Community Treasure Hunt

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

Start Hunting!

Translated by