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

 採用された回答

Voss
Voss 2024 年 1 月 25 日

0 投票

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 件のコメント

Turbulence Analysis
Turbulence Analysis 2024 年 1 月 25 日
Thanks!
Turbulence Analysis
Turbulence Analysis 2024 年 1 月 25 日
How to identify the condition to store the image?
if ... % if some condition says to store this B in Img
Img(:,:,end+1) = B;
end
Voss
Voss 2024 年 1 月 25 日
That's up to you. How should it work? For example, is it the case that "some process" generates an image only on random iterations, but every time "some process" generates an image you want to store it?
Turbulence Analysis
Turbulence Analysis 2024 年 1 月 25 日
In the attached file, ts is the time stamps in microseconds. x, y is the image cordinates (1280 x 720) and p represents the intensity.
For each image, I need to accumulate the events corresponds to 200 micro seconds i.e. for first image ts 68942 - 69142 and next 200 micro seconds i.e. 69143 - 69342 for second image and so on...
Voss
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
Turbulence Analysis
Turbulence Analysis 2024 年 1 月 25 日
Thanks very much!

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

その他の回答 (2 件)

Matt J
Matt J 2024 年 1 月 25 日
編集済み: Matt J 2024 年 1 月 25 日

0 投票

One way,
Img=nan(M,N,a);
Isubset=[10 47, 150,...,a]
for i = 1:a
B = some process % my image
if ismember(i,Isubset)
Img(:,:,i) = B;
end
end

1 件のコメント

Turbulence Analysis
Turbulence Analysis 2024 年 1 月 25 日
移動済み: Voss 2024 年 1 月 25 日
Hi Matt,
Actually iteration number 10, 150 is just an example, in reality these numbers are highly random.

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

Matt J
Matt J 2024 年 1 月 25 日
編集済み: Matt J 2024 年 1 月 25 日

0 投票

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

質問済み:

2024 年 1 月 25 日

編集済み:

2024 年 1 月 25 日

Community Treasure Hunt

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

Start Hunting!

Translated by