# clarification in for loop with intervals

27 views (last 30 days)
Hi,
I am running the for loop with the intervals as shown below, here at the end of each sequence I need to save the average image for e.g.55 to 65, then that particular matrix needs to be cleared then continue with next seqeunce i.e. 125:1:145 and so on.. Is there a way to do this ???
for kk = [55:1:65 125:1:145 201:1:225]
% my code
end
##### 2 CommentsShowHide 1 older comment
Turbulence Analysis on 20 Jan 2021
for kk = [55:1:65 125:1:145 201:1:225]
if (kk>=1) && (kk<=9)
fname_strt = 'B0000' ;
elseif (kk>=10) && (kk<=99)
fname_strt='B000';
elseif (kk>=100) && (kk<=999)
fname_strt='B00';
elseif (kk>=1000) && (kk<=9999)
fname_strt='B0';
else
fname_strt='B';
end
fname_end = num2str(kk);
fname = strcat(fname_strt,fname_end,'.vc7');
x=(II.x);
y=(II.y);
v = II.vx;
fu2=flipud(v);
t1 = 1;
skT = 1;
skx = 1;
sky = 1;
skT = 1;
lx1 = 1;
lx2 = 89;
ly1 = 1;
ly2 = 97;
fu2 = medfilt2(fu2,[M M]);
U(:,:,((kk-t1+1)-1)/skT+1) = fu2(lx1:skx:lx2,ly1:sky:ly2);
kk
end
X2 = Mean (U);
imagesc (U);
Clear U
In the above, for each loop interval, I have to calculate the average of matrix U and save the resultant image, then matrix U needs to be deleted before moving to the second interval 125:1:145

per isakson on 20 Jan 2021
Someting like this
%%
indicies = {[55:1:65], [125:1:145], [201:1:225]};
for jj = 1 : numel( indicies )
for kk = indicies{jj}
% my code
end
% save average
end
Turbulence Analysis on 20 Jan 2021
Amazing, It is working perfectly.. Thanks a lot...