double loop formation question

1 次查看(过去 30 天)
Hello,
I have a doubt about the possibility of forming another loop of following repetation (the size of GWdepth is 74*100*1566, 74 and 100 indicate the lon and lat):
j = 1
for i = 1:30
depth_week_j(:,:,i) = GWdepth(:,:,j);
j = j + 52
end
mean_depth_week_j(:,:,1) = nanmean(depth_week_j,3);
j = 2
for i = 1:30
depth_week_j(:,:,i) = GWdepth(:,:,j);
j = j + 52
end
mean_depth_week_j(:,:,2) = nanmean(depth_week_j,3);
...... I need to repeat this process for 52 times until j = 52,
j = 52
for i = 1:30
depth_week_j(:,:,i) = GWdepth(:,:,j);
j = j + 52
end
mean_depth_week_j(:,:,52) = nanmean(depth_week_j,3);
Any ideas on how to form a double loop based on this condition?

采纳的回答

David Hill
David Hill 2020-4-3
for j=1:52
jj=j;
for i = 1:30
depth_week_j(:,:,i) = GWdepth(:,:,jj);
jj = jj + 52;
end
mean_depth_week_j(:,:,j) = nanmean(depth_week_j,3);
end

更多回答(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