Filter löschen
Filter löschen

Index exceeds matrix dimensions

1 Ansicht (letzte 30 Tage)
Maroulator
Maroulator am 11 Aug. 2014
Bearbeitet: Image Analyst am 11 Aug. 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

Akzeptierte Antwort

Image Analyst
Image Analyst am 11 Aug. 2014
Bearbeitet: Image Analyst am 11 Aug. 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;

Weitere Antworten (0)

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by