clarification in for loop with intervals

12 vues (au cours des 30 derniers jours)
Turbulence Analysis
Turbulence Analysis le 20 Jan 2021
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 commentaires
dpb
dpb le 20 Jan 2021
What's in the loop?
May not need it; certainly not in that form...
Turbulence Analysis
Turbulence Analysis le 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');
II = loadvec(fname);
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

Connectez-vous pour commenter.

Réponse acceptée

per isakson
per isakson le 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
  1 commentaire
Turbulence Analysis
Turbulence Analysis le 20 Jan 2021
Amazing, It is working perfectly.. Thanks a lot...

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

Community Treasure Hunt

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

Start Hunting!

Translated by