NANMEANs for each (n,m) position over several matrices with the same size

16 views (last 30 days)
Hi all,
I have a number of matrices with the same size. What I need is a nanmean for each position of the matrices over all matrices, i.e.:
A=[1 2 NAN;4 5 6;7 NAN 9] B=[NAN 2 3;NAN NAN 6;7 8 9] C=[NAN NAN NAN; 4 5 6;7 8 9]
Result:
(1,1) = nanmean(1 NAN NAN) (1,2) = nanmean(2 2 NAN) ... (3,3) = nanmean(9 9 9)
Thank you!

Accepted Answer

Wayne King
Wayne King on 27 Nov 2013
Not sure if this is what you're asking but:
A=[1 2 NaN;4 5 6;7 NaN 9];
B=[NaN 2 3;NaN NaN 6;7 8 9];
C=[NaN NaN NaN; 4 5 6;7 8 9];
Z = cat(3,A,B,C);
nanmean(Z,3)

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!