Find the mean of a multidimensional array over multiple dimensions.
Create a 2-by-5-by-3 array
X
with some missing values.
X =
X(:,:,1) =
1 3 5 7 9
2 4 6 8 NaN
X(:,:,2) =
NaN 13 15 17 19
NaN 14 16 18 20
X(:,:,3) =
21 23 NaN 27 29
22 24 26 28 30
Find the mean of each page of
X
by specifying dimensions 1 and 2 as the operating dimensions.
ypage =
ypage(:,:,1) =
ypage(:,:,2) =
16.5000
ypage(:,:,3) =
25.5556
For example,
ypage(1,1,1)
is the mean of the non-
NaN
elements in
X(:,:,1)
.
Find the mean of the elements in each
X(i,:,:)
slice by specifying dimensions 2 and 3 as the operating dimensions.
yrow = 2×1
14.5385
16.7692
For example,
yrow(2)
is the mean of the non-
NaN
elements in
X(2,:,:)
.