Filter löschen
Filter löschen

How to average more than 50 3D matrices using nanmean

1 Ansicht (letzte 30 Tage)
raheem mian
raheem mian am 14 Nov. 2019
Bearbeitet: Matt J am 15 Nov. 2019
Hi, I am trying to average a lot of 3D matrices using NaNmean. I have tried using cat but my 3D matrices are huge (351x400x400) which is using a lot of memory. Is there a better way to do this ?
  7 Kommentare
Adam Danz
Adam Danz am 14 Nov. 2019
Bearbeitet: Adam Danz am 14 Nov. 2019
Hmmmm... concatenating 50 arrays that each have more than 56 million elements isn't going to happen.
Off the bat I can think of a couple ideas.
1) Using 2 loops, you can loop through each file and partially load each 351 x 400 slice so you have 50 of those matricies which would make ~7m data points. If that's still too large you could partially load in each 351x1 column. Then you can do element-wise averaging and store the values as you proceed through the loops. That would involve 50 x 400 loops which isn't a big deal.
2) you can reorganize your data as tall arrays which are designed for large amounts of data.
raheem mian
raheem mian am 14 Nov. 2019
This idea is perfect, Thank you!

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Matt J
Matt J am 14 Nov. 2019
Bearbeitet: Matt J am 15 Nov. 2019
Here's what I would do, I suppose. It assumes each of your .mat files stores the volume under the name 'a'.
Summation=0;
NCounter=0;
files=dir(fullfile('yourFolder','*.mat'));
for i=1:numel(files)
S=load(fullfile('yourFolder',files(i).name));
map=isnan(S.a);
S.a(map)=0;
Summation = Summation + S.a;
NCounter = NCounter + (~map);
end
result = Summation./Ncounter;
  2 Kommentare
raheem mian
raheem mian am 14 Nov. 2019
Bearbeitet: raheem mian am 14 Nov. 2019
I like this method too ! Thanks. Method seems faster.
Adam Danz
Adam Danz am 14 Nov. 2019
Yep, this is simple and fast!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by