Index exceeds matrix dimensions

1 回表示 (過去 30 日間)
Maroulator
Maroulator 2014 年 8 月 11 日
編集済み: Image Analyst 2014 年 8 月 11 日
I have the code below, but I don't understand why it is that my index exceeds matrix dimensions.
i=1;
for min=0:60:240
hour(i)=min(i+1)/60;
i=i+1;
end
I also tried the code below to work around the error, but I am still getting it. Any takers?
min=0:60:240;
for i=1:length(min)
hour(i)=min(i+1)/60;
end
  1 件のコメント
Image Analyst
Image Analyst 2014 年 8 月 11 日
I fixed your formatting but request you read this so you know how to do it yourself next time: http://www.mathworks.com/matlabcentral/answers/13205-tutorial-how-to-format-your-question-with-markup

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

採用された回答

Image Analyst
Image Analyst 2014 年 8 月 11 日
編集済み: Image Analyst 2014 年 8 月 11 日
min() is a built in function. You've done something very bad by using it as your variable name.
But since you've destroyed the min function, it's now a variable with length of length(min). So what index are you at when i = length(min)? You have min(length(min)+1) which is past the end of your badly-named variable. Just say:
minIndex = 0:60:240;
for i=1:length(minIndex)
hour(i) = minIndex(i)/60;
end
Or
minIndex = 0:60:240;
for i = minIndex
hour(i) = i / 60;
end
Or, even better
minIndex = 0:60:240;
hour = minIndex / 60;

その他の回答 (0 件)

カテゴリ

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