summing along 3rd dimension every 10 frames

4 ビュー (過去 30 日間)
Lucrezia Cester
Lucrezia Cester 2019 年 11 月 14 日
コメント済み: the cyclist 2019 年 11 月 14 日
Hello,
I have a matrix of 32x32x2500.
I would like to sum it along the third dimension so to have a matrix of 32x32x250 so that along the third dimesion i have summed 10 paged together thus increasing my SNR.
I have tried with something like
sumby10 = zeros(32,32,2500);
for a = 1:11:2500
sumby10(:,:,a) = sum(micron_59frames(:,:,a:a+9),3);
end
but this does not work as it return a matrix of 32x32x2500.
Could someone help please?

採用された回答

Philippe Lebel
Philippe Lebel 2019 年 11 月 14 日
I would do:
sumby10 = zeros(32,32,250);
for a = 1:250
sumby10(:,:,a) = sum(micron_59frames(:,:,(a-1)*10+1:(a)*10),3);
end

その他の回答 (2 件)

Stephan
Stephan 2019 年 11 月 14 日
編集済み: Stephan 2019 年 11 月 14 日
If A is your matrix:
B = sum(reshape(A,32,32,10,[]),3);

the cyclist
the cyclist 2019 年 11 月 14 日
編集済み: the cyclist 2019 年 11 月 14 日
Stephan provided a slick one-liner, but I think it might also be useful for you to see what mistakes you made. Here is a corrected version of your original code:
sumby10 = zeros(32,32,250);
for a = 1:250
idx = (a-1)*10+1:a*10;
sumby10(:,:,a) = sum(micron_59frames(:,:,idx),3);
end
Note a couple things that are different:
  • I preallocated sumby10 to be only length 250 in dimension 3. Your preallocation guaranteed that your result would be the full 2500 in length
  • I re-did the loop index. You were using the loop index "a" to write into "slices" 1,11,22,33 etc of the sumby10 matrix. You were leaving the in-between rows equal to zero -- but they were there.
  • You were confusing the indexing of the old matrix (needed to span all 2500 rows) with indexing of the new matrix (only needs to span 250 rows)
  2 件のコメント
Philippe Lebel
Philippe Lebel 2019 年 11 月 14 日
HaHA, i got you!
the cyclist
the cyclist 2019 年 11 月 14 日
¯\_(ツ)_/¯

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

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by