double loop formation question

1 vue (au cours des 30 derniers jours)
kim chan
kim chan le 3 Avr 2020
Commenté : kim chan le 4 Avr 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?

Réponse acceptée

David Hill
David Hill le 3 Avr 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
  1 commentaire
kim chan
kim chan le 4 Avr 2020
thank you so much!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by