clarification in for loop with intervals

조회 수: 26 (최근 30일)
Turbulence Analysis
Turbulence Analysis 2021년 1월 20일
댓글: 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 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