Main Content

nanmean

(不建议)卑鄙,忽略values

nanmean不建议。Use the MATLAB®functionmean反而。With themean功能,您可以指定是包括还是省略计算值。有关更多信息,请参阅Compatibility Considerations

Description

例子

y= nanmean(X返回mean元素X,删除后计算all值。

  • IfX是a vector, thennanmean(X)是the mean of all the non-elements ofX

  • IfX是a matrix, thennanmean(X)是列均值的行矢量,在删除后计算值。

  • IfX是a multidimensional array, thennanmeanoperates along the first nonsingleton dimension ofX。这size of this dimension becomes 1 while the sizes of all other dimensions remain the same.nanmean删除一切值。

有关如何nanmean所有人的对待阵列values, seeTips

例子

y= nanmean(X,'全部')返回mean of all elements ofX,删除后计算值。

例子

y= nanmean(X,,,,暗淡返回沿操作维度的平均值暗淡ofX,删除后计算值。

例子

y= nanmean(X,,,,vecdim返回在向量中指定的尺寸上的平均值vecdim。这function computes the means after removing值。例如,如果X是a matrix, thennanmean (X, [1 - 2])是所有非 -elements ofXbecause every element of a matrix is contained in the array slice defined by dimensions 1 and 2.

Examples

全部收缩

找到具有缺失值的矩阵数据的列均值。

x =魔术(3);x([1 6:9])= nan
x =3×3nan 1 nan 3 5 nan 4 nan nan
y =nanmean(X)
y =1×33.5000 3.0000南

在数组中找到所有值的平均值,忽略缺失值。

创建一个2 x-5 x-3阵列Xwith some missing values.

x =reshape(1:30,[2 5 3]); X([10:12 25]) = NaN
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

找到元素的平均值X

y =nanmean(X,'全部'
y =15.6538

Find the row means for matrix data with missing values by specifying to compute the means along the second dimension.

x =魔术(3);x([1 6:9])= nan
x =3×3nan 1 nan 3 5 nan 4 nan nan
y = nanmean(x,2)
y =3×11 4 4

在多个维度上找到多维阵列的平均值。

创建一个2 x-5 x-3阵列Xwith some missing values.

x =reshape(1:30,[2 5 3]); X([10:12 25]) = NaN
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

找到每页的平均值Xby specifying dimensions 1 and 2 as the operating dimensions.

ypage = nanmean(x,[1 2])
ypage = ypage(:,:,:,1)= 5 ypage(::,:,:,2)= 16.5000 ypage(:,:,:,3)= 25.5556

For example,ypage(1,1,1)是the mean of the non-元素x(:,:,1)

找到每个元素的平均值x(i,:,::)通过将尺寸2和3指定为操作尺寸来切片。

yrow =nanmean(X,[2 3])
yrow =2×114.5385 16.7692

For example,YOW(2)是the mean of the non-元素x(2,:,,:)

输入参数

全部收缩

输入数据,指定为标量,向量,矩阵或多维数组。

IfX是一个空数组,然后nanmean(X)。有关更多详细信息,请参阅Tips

数据类型:单身的|双倍的

沿着操作的维度,,,,specified as a positive integer scalar. If you do not specify a value, then the default value is the first array dimension whose size does not equal 1.

暗淡指示长度降至1的尺寸。尺寸(Y,昏暗)为1,而所有其他维度的大小保持不变。

Consider a two-dimensional arrayX

  • If暗淡等于1,然后Nanmean(x,1)返回a row vector containing the mean for each column.

  • If暗淡等于2,然后Nanmean(x,2)返回包含每行平均值的列向量。

If暗淡是greater thanndims(x)或者如果大小(x,昏暗)是1,然后nanmean返回X

数据类型:单身的|双倍的

尺寸向量,指定为正整数矢量。每个元素vecdim表示输入数组的维度X。这outputyhas length 1 in the specified operating dimensions. The other dimension lengths are the same forXandy

例如,如果X是一个2 x-3 x-3阵列,然后nanmean (X, [1 - 2])返回a 1-by-1-by-3 array. Each element of the output is the mean of the elements on the corresponding page ofX

数据类型:单身的|双倍的

输出参数

全部收缩

Mean values, returned as a scalar, vector, matrix, or multidimensional array.

Tips

  • Whennanmean计算所有数组的平均值值,阵列是空的删除值,因此,其余元素的总和为0。因为平均计算涉及通过0,,,,the mean value is。这output不是值。

扩展功能

版本历史记录

Introduced before R2006a

展开全部

不建议从R2020B开始

也可以看看

|