clarification in for loop with intervals

26 ビュー (過去 30 日間)
Turbulence Analysis
Turbulence Analysis 2021 年 1 月 20 日
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 件のコメント
dpb
dpb 2021 年 1 月 20 日
What's in the loop?
May not need it; certainly not in that form...
Turbulence Analysis
Turbulence Analysis 2021 年 1 月 20 日
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

サインインしてコメントする。

採用された回答

per isakson
per isakson 2021 年 1 月 20 日
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 件のコメント
Turbulence Analysis
Turbulence Analysis 2021 年 1 月 20 日
Amazing, It is working perfectly.. Thanks a lot...

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by