MATLAB Answers

Calculating median along specific dimension of 3D array

8 ビュー (過去 30 日間)
Uerm
Uerm 2019 年 11 月 27 日
コメント済み: Uerm 2019 年 11 月 28 日
Hi,
I have a 3D array (S) of size 75x31253x1523. If I was to calculate the median along the second axis (for each row) it would be median(S,2) which would result in a 75x1x1523 array.
However, because the array is large, I run out of memory when I try to calculate the median of the whole array with one line. Therefore, I want to calculate the median in chunks. The problem is that each chunk will be of size Ax1xB. When stacking them together, they will be of size AxNxB. How can I calculate it in chunks and still end with size Ax1xB (75x1x1523)?
Thanks!

  2 件のコメント

Stephen Cobeldick
Stephen Cobeldick 2019 年 11 月 27 日
Check your available memory, it works when I tried it (32 bit R2012b):
>> S = randi(75,31253,1523);
>> M = median(S,2);
>>
You might be able to increase your swap space, which although slow can be effective in avoiding such errors.
Uerm
Uerm 2019 年 11 月 27 日
Sorry, I wrote the dimensions wrong. They are 90x38021x1633. However, they are from other calculations and take up approximately 22.5 gb of space.
Can I increase the swap space when I use a mac?

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

採用された回答

Matt J
Matt J 2019 年 11 月 28 日
編集済み: Matt J 2019 年 11 月 28 日
M=nan(90,1,1633);
for i=1:90
M(i,:,:)=median(S(i,:,:),2);
end

  1 件のコメント

Uerm
Uerm 2019 年 11 月 28 日
Works like a charm. Thank you!

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

その他の回答 (0 件)

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by