Index exceeds matrix dimensions error when attempt to create a recursion

1 回表示 (過去 30 日間)
Faris Shahin
Faris Shahin 2017 年 4 月 20 日
回答済み: Sudarshan Kolar 2017 年 4 月 24 日
Hi, I am trying to create a recursion using this code but get 'Index exceeds matrix dimensions' error. What does it means and how do I correct the code?
Thank you
numlay=input('Number of layers= ');
phi(1)=30;
for m=[1:numlay]
n(m)=input('Insert Re(n) =');
phiR(m+1)=Snells(n(m),n(m+1),phi(m));
end

回答 (1 件)

Sudarshan Kolar
Sudarshan Kolar 2017 年 4 月 24 日
Hello Faris,
I understand that you are getting index exceeds matrix dimension error. This is because the variable 'phi' is a scalar (only one value) and in the loop you are trying to access phi(m), where m = 1:numlay.
You will get this error whenever you access an out of bound element from an array.
Hope that helps.
Sudarshan

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by