Effacer les filtres
Effacer les filtres

Index exceeds matrix dimensions

1 vue (au cours des 30 derniers jours)
Maroulator
Maroulator le 11 Août 2014
Modifié(e) : Image Analyst le 11 Août 2014
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 commentaire
Image Analyst
Image Analyst le 11 Août 2014
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

Connectez-vous pour commenter.

Réponse acceptée

Image Analyst
Image Analyst le 11 Août 2014
Modifié(e) : Image Analyst le 11 Août 2014
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;

Plus de réponses (0)

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by