How to loop over this lines?

2 次查看(过去 30 天)
Lilya
Lilya 2019-2-6
评论: Lilya 2019-2-6
Hi all,
could anyone help to creat a loop over the folloing lines?
Thanks a lot for the help.
SW_NRS = nan(11,8,960);
SW = SWGNTWTR{1,1}(NRS_lat,NRS_lon,1:24);
SW_NRS (1:11,1:8,1:24)= SW;
SW = SWGNTWTR{2,1}(NRS_lat,NRS_lon,1:24);
SW_NRS (1:11,1:8,25:48)= SW;
SW = SWGNTWTR{3,1}(NRS_lat,NRS_lon,1:24);
SW_NRS (1:11,1:8,49:72)= SW;
SW = SWGNTWTR{4,1}(NRS_lat,NRS_lon,1:24);
SW_NRS (1:11,1:8,73:96)= SW;
SW = SWGNTWTR{5,1}(NRS_lat,NRS_lon,1:24);
SW_NRS (1:11,1:8,97:120)= SW;
SW = SWGNTWTR{6,1}(NRS_lat,NRS_lon,1:24);
SW_NRS (1:11,1:8,121:144)= SW;
SW = SWGNTWTR{7,1}(NRS_lat,NRS_lon,1:24);
SW_NRS (1:11,1:8,145:168)= SW;
SW = SWGNTWTR{8,1}(NRS_lat,NRS_lon,1:24);
SW_NRS (1:11,1:8,169:192)= SW;
SW = SWGNTWTR{9,1}(NRS_lat,NRS_lon,1:24);
SW_NRS (1:11,1:8,193:216)= SW;
SW = SWGNTWTR{10,1}(NRS_lat,NRS_lon,1:24);
SW_NRS (1:11,1:8,217:240)= SW;

采纳的回答

Rik
Rik 2019-2-6
You mean like this?
SW_NRS = nan(11,8,960);
for k=1:(size(SW_NRS,3)/24)
SW = SWGNTWTR{1,k}(NRS_lat,NRS_lon,1:24);
SW_NRS (1:11,1:8,(1:24)+24*(k-1))= SW;
end
  3 个评论
Rik
Rik 2019-2-6
I see what went wrong: I wrote {1,k} instead of {k,1}. If you switch those around you should get what you need.
SW_NRS = nan(11,8,960);
for k=1:(size(SW_NRS,3)/24)
SW = SWGNTWTR{k,1}(NRS_lat,NRS_lon,1:24);
SW_NRS (1:11,1:8,(1:24)+24*(k-1))= SW;
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