Index exceeds number of array elements (181)
조회 수: 1 (최근 30일)
이전 댓글 표시
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
Torsten
2019년 6월 11일
편집: Torsten
2019년 6월 11일
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))
답변 (1개)
Jan
2019년 6월 11일
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))
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!