Problem with the looping

1 次查看(过去 30 天)
Sophia
Sophia 2016-3-30
编辑: Sophia 2016-3-30
tr(i,j,ni) is 361*361*432
ind=10:16; % Winter average over month Oct to following year's April
for k=1:(ni/12)-1
meanr = nanmean(tr(i,j,ind));
tmeanr(i,j,k) = meanr;
ind = ind + 12;
end
The values in * *meanr* = nanmean(tr(i,j,ind));* are showing all zeros.
ind values showing are 430-436, but since i don't have the complete winter data values for 2014(i just have oct to dec for 2014 not jan to apr 2015), so i want this ind to show 418-424 instead.

采纳的回答

Image Analyst
Image Analyst 2016-3-30
Use an "if" to check for that value and if the value is in the "missing" range then either "continue" or subtract 12 from ind to get it into the range you want.
Or else insert data for the "missing" months, like zeros or something, so that it will have something there in the right spot.
  1 个评论
Sophia
Sophia 2016-3-30
编辑:Sophia 2016-3-30
I tried this, and it works,But the means still show zeros
t_r = zeros(361,361,35);
ind=10:16;
for t=1:(ni/12)-1;
if t<=34
wint_tr = nanmean(tr(i,j,ind));
t_r(i,j,t) = wint_tr;
ind = ind + 12;
else
end
end
* *mean_winter_sid = mean(t_r,3);** all values in this are showing zero

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by