필터 지우기
필터 지우기

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 CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by