save images inside a for loop at uneven intervals
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi,
I am trying to save images inside the Img array that is generated inside the for loop at uneven iteration numbers. For example sometimes image generated at 10th iteration, while sometimes it's at 150th iteration. How to handle this?
for i = 1:a
B = some process % my image
Img(:,:,) = B
end
댓글 수: 0
채택된 답변
Voss
2024년 1월 25일
Here's one way that may work for your particular task:
Img = zeros(0,0,0);
for i = 1:a
B = some process % my image
if ... % if some condition says to store this B in Img
Img(:,:,end+1) = B;
end
end
댓글 수: 6
Voss
2024년 1월 25일
Maybe something along these lines:
Img = zeros(0,0,0);
last_stored_time = ts(1);
for i = 1:a
B = some process % my image
if ts(i) - last_stored_time >= 200
Img(:,:,end+1) = B;
last_stored_time = ts(i);
end
end
추가 답변 (2개)
Matt J
2024년 1월 25일
편집: Matt J
2024년 1월 25일
If you don't know in advance which and how many loop iterations you'll be storing, it would be best to accumulate them in a cell array, and then post-concatenate:
Img = cell(1,a);
for i = 1:a
B = some process % my image
if ... % if some condition says to store this B in Img
Img{i} = B;
end
end
Img=cat(3,Img{:}); %empty cells are discarded
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!