double loop formation question

1 Ansicht (letzte 30 Tage)
kim chan
kim chan am 3 Apr. 2020
Kommentiert: kim chan am 4 Apr. 2020
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?

Akzeptierte Antwort

David Hill
David Hill am 3 Apr. 2020
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

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by