MATLAB Answers

How to find the mean of 12 different 3-D arrays containing nan so that I can omitnan in the final calculations?

2 views (last 30 days)
I have 12 different 3-D arrays, say A, B, C, D, E, F, G, H, I, J, K, L, each of them having the dimension of 60x57x372. All of them contain several NaN values. I want to calculate the mean of these arrays to get an array of same dimension, that is of 60x57x372. How to do that?

Accepted Answer

madhan ravi
madhan ravi on 30 May 2021
Use mean() with "Omitnan" flag
help mean
MEAN Average or mean value. S = MEAN(X) is the mean value of the elements in X if X is a vector. For matrices, S is a row vector containing the mean value of each column. For N-D arrays, S is the mean value of the elements along the first array dimension whose size does not equal 1. MEAN(X,'all') is the mean of all elements in X. MEAN(X,DIM) takes the mean along the dimension DIM of X. MEAN(X,VECDIM) operates on the dimensions specified in the vector VECDIM. For example, MEAN(X,[1 2]) operates on the elements contained in the first and second dimensions of X. S = MEAN(...,OUTTYPE) specifies the type in which the mean is performed, and the type of S. Available options are: 'double' - S has class double for any input X 'native' - S has the same class as X 'default' - If X is floating point, that is double or single, S has the same class as X. If X is not floating point, S has class double. S = MEAN(...,NANFLAG) specifies how NaN (Not-A-Number) values are treated. The default is 'includenan': 'includenan' - the mean of a vector containing NaN values is also NaN. 'omitnan' - the mean of a vector containing NaN values is the mean of all its non-NaN elements. If all elements are NaN, the result is NaN. Example: X = [1 2 3; 3 3 6; 4 6 8; 4 7 7] mean(X,1) mean(X,2) Class support for input X: float: double, single integer: uint8, int8, uint16, int16, uint32, int32, uint64, int64 See also MEDIAN, STD, MIN, MAX, VAR, COV, MODE. Documentation for mean doc mean Other functions named mean codistributed/mean duration/mean tall/mean datetime/mean fints/mean timeseries/mean dlarray/mean gpuArray/mean
  3 Comments

Sign in to comment.

More Answers (0)

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!