Effacer les filtres
Effacer les filtres

Index exceeds number of array elements (181)

1 vue (au cours des 30 derniers jours)
Tarek Zaqout
Tarek Zaqout le 11 Juin 2019
Réponse apportée : Jan le 11 Juin 2019
Hi,
I have this error while I'm using this code. I can't seem to find the source of the error.
for i=11:length(Tjord)
if nanmean(Tair(i)+Tair(i-1)+Tair(i-2)+Tair(i-3)+Tair(i-4)+Tair(i-5)+Tair(i-6)+Tair(i-7)+Tair(i-8)+Tair(i-9)+Tair(i-10))>10
Tjord(i)=Tjord(i-1)+(Tair(i)-Tair(i-3))*0.5;
elseif nanmean(Tair(i)+Tair(i-1)+Tair(i-2)+Tair(i-3)+Tair(i-4)+Tair(i-5)+Tair(i-6)+Tair(i-7)+Tair(i-8)+Tair(i-9)+Tair(i-10))>5
if Snowdepth(i)>0
Tjord(i)=Tjord(i-1)+(Tair(i)-Tair(i-5))*0.01;
else %no snow
Tjord(i)=Tjord(i-1)+(Tair(i)-Tair(i-3))*0.025;
end
elseif Tjord(i-1)==0
Tjord(i)=0;
else %WINTER; avg. Tair is below 2.5°C
if Snowdepth(i)>0
Tjord(i)=0;%Tjord(i-1)+(Tair(i)-Tair(i-5))*0.001;
else %frost and no snow
Tjord(i)=Tjord(i-1)+(Tair(i)-Tair(i-10))*0.001;
end
end
RMSE(i) = sqrt(mean((Tjord(i) - TIMETABLE_ALL_cal{i,3}).^2));
end
  2 commentaires
Torsten
Torsten le 11 Juin 2019
Modifié(e) : Torsten le 11 Juin 2019
Maybe "Snowdepth" , "Tair" and/or "TIMETABLE_ALL_cal" have less elements than "Tjord" ?
And in the definition of "RMSE" you calculate the mean of a single element which looks strange to me.
Same for
nanmean(Tair(i)+Tair(i-1)+Tair(i-2)+Tair(i-3)+Tair(i-4)+Tair(i-5)+Tair(i-6)+Tair(i-7)+Tair(i-8)+Tair(i-9)+Tair(i-10))
Mohammad Alhashash
Mohammad Alhashash le 11 Juin 2019
Can you post down the the complete error statments

Connectez-vous pour commenter.

Réponses (1)

Jan
Jan le 11 Juin 2019
Use the debugger to examine the cause of the problems. Type this in the command window:
dbstop if error
Then run the code again. When it stops at the error. check the sizes of the variables used in the failing line.
By the way, simplify:
if nanmean(Tair(i)+Tair(i-1)+Tair(i-2)+Tair(i-3)+Tair(i-4)+Tair(i-5)+Tair(i-6)+Tair(i-7)+Tair(i-8)+Tair(i-9)+Tair(i-10))>10
Tjord(i)=Tjord(i-1)+(Tair(i)-Tair(i-3))*0.5;
elseif nanmean(Tair(i)+Tair(i-1)+Tair(i-2)+Tair(i-3)+Tair(i-4)+Tair(i-5)+Tair(i-6)+Tair(i-7)+Tair(i-8)+Tair(i-9)+Tair(i-10))>5
To
tmp = sum(Tair(i:-1:i-10));
if tmp > 10
...
elseif tmp > 5
...
The nanmean function is not useful here, because you provide a scalar as input only. Maybe you really want nanmean instead. Then:
tmp = nanmean(Tair(i:-1:i-10))

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