Documentation

movemean

Moving mean

Syntax

m = movmean(a,k)
m = movmean(a,[kb kf])
m =movemean(___,dim)
m =movemean(___,nanflag)
m =movemean(___,名称,值)

描述

example

m =movemean(A,k)返回一系列本地k-pointmeanvalues, where each mean is calculated over a sliding window of lengthk跨越相邻元素A. Whenkis odd, the window is centered about the element in the current position. Whenk即使是,窗口都集中在当前和以前的元素上。当没有足够的元素填充窗口时,窗口大小会自动在端点上截断。当窗口被截断时,平均值仅在填充窗口的元素上占用。M大小与A.

  • 如果A是一个向量,然后movemeanoperates along the length of the vector.

  • 如果Ais a multidimensional array, thenmovemean沿着第一arra运作y dimension whose size does not equal 1.

example

m =movemean(A,[kb kf])computes the mean with a window of lengthKB+kf+1其中包括当前位置中的元素KB元素向后,KFelements forward.

example

m =movemean(___,dim)returns the array of moving averages along dimensiondim对于以前的任何语法。例如,如果Ais a matrix, thenmovemean(A,k,2)operates along the columns ofA, computing thek-element sliding mean for each row.

example

m =movemean(___,nanflag)specifies whether to include or omitvalues from the calculation for any of the previous syntaxes.movmean(a,k,'includeenan')包括全部计算中的值movmean (k ' omitnan ')ignores them and computes the mean over fewer points.

example

m =movemean(___,名称,价值)specifies additional parameters for the moving average using one or more name-value pair arguments. For example, ifxis a vector of time values, thenmovemean(A,k,'SamplePoints',x)computes the moving average relative to the times inx.

例子

全部收缩

Compute the three-point centered moving average of a row vector. When there are fewer than three elements in the window at the endpoints, take the average over the elements that are available.

A = [4 8 6 -1 -2 -3 -1 3 4 5]; M = movmean(A,3)
m =列1至7 6.0000 6.0000 4.3333 1.0000 -2.0000 -2.0000 -0.3333列8至10 2.0000 4.0000 4.5000

计算行矢量的三点尾随移动平均线。当端点处的窗口中的元素少于三个元素时,请以平均值来超过可用元素。

A = [4 8 6 -1 -2 -3 -1 3 4 5]; M = movmean(A,[2 0])
m =列1至7 4.0000 6.0000 6.0000 4.3333 1.0000 -2.0000 -2.0000列8至10 -0.3333 2.0000 4.0000

Compute the three-point centered moving average for each row of a matrix. The window starts on the first row, slides horizontally to the end of the row, then moves to the second row, and so on. The dimension argument is two, which slides the window across the columns ofA.

A = [4 8 6; -1 -2 -3; -1 3 4]
A =4 8 6 -1 -2 -3 -1 3 4
m = movmean(a,3,2)
m =6.0000 6.0000 7.0000 -1.5000 -2.0000 -2.5000 1.0000 2.0000 3.5000

Compute the three-point centered moving average of a row vector containing twoelements.

A = [4 8 NaN -1 -2 -3 NaN 3 4 5]; M = movmean(A,3)
m =Columns 1 through 7 6.0000 NaN NaN NaN -2.0000 NaN NaN Columns 8 through 10 NaN 4.0000 4.5000

重新计算平均水平,但省略了values. Whenmovemeandiscardselements, it takes the average over the remaining elements in the window.

m = movemean(a,3,'omitnan')
m =列1至7 6.0000 6.0000 3.5000 -1.5000 -2.0000 -2.5000 0列8至10 3.5000 4.0000 4.5000

Compute a 3-hour centered moving average of the data inA根据时间向量t.

A = [4 8 6 -1 -2 -3]; k = hours(3); t = datetime(2016,1,1,0,0,0) + hours(0:5)
t = 1x6 DateTime数组列1至3 01-JAN-2016 00:00:00 01-JAN-2016 01:00:00 01-1016-2016 02:00:00列4至6 01-JAN-JAN-2016-2016 03:00:00 01-JAN-2016 04:00:00 01-JAN-2016 05:00:00
m = movemean(a,k,'SamplePoints',T)
M = 6.0000 6.0000 4.3333 1.0000 -2.0000 -2.5000

Compute the three-point centered moving average of a row vector, but discard any calculation that uses fewer than three points from the output. In other words, return only the averages computed from a full three-element window, discarding endpoint calculations.

A = [4 8 6 -1 -2 -3 -1 3 4 5]; M = movmean(A,3,'Endpoints','丢弃')
m =Columns 1 through 7 6.0000 4.3333 1.0000 -2.0000 -2.0000 -0.3333 2.0000 Column 8 4.0000

输入参数

全部收缩

输入数组, specified as a vector, matrix, or multidimensional array.

数据类型:single|双倍的|int8|int16|INT32|INT64|UINT8|UINT16|uint32|uint64|logical

窗口长度,指定为数字或持续时间标量。什么时候kis a positive integer scalar, the centered average includes the element in the current position plus surrounding neighbors. For example, a three-point average defined by a window of length three results in the following calculation for a vectorA:

数据类型:single|双倍的|int8|int16|INT32|INT64|UINT8|UINT16|uint32|uint64|期间

定向窗口长度,指定为包含两个元素的数字或持续时间行矢量。什么时候KBandKFare positive integer scalars, the calculation is overKB+kf+1elements. The calculation includes the element in the current position,KB当前位置之前的要素,KF当前位置之后的元素。例如,定向窗口定义的四点平均值[2 1]results in the following calculation for a vectorA:

数据类型:single|双倍的|int8|int16|INT32|INT64|UINT8|UINT16|uint32|uint64|期间

沿着操作的维度,指定为正整数标量。如果未指定值,则默认值是第一个数组维度,其大小不等于1。

方面dimindicates the dimension thatmovemean运行,也就是说,the direction in which the specified window slides.

考虑二维输入阵列,A.

  • 如果dim = 1, thenmovemean(A,k,1)starts with the first column and slides vertically over each row. The mean is computed overk一次元素。Then it moves to the second column and repeats the computation. This process continues until all columns are exhausted.

  • 如果dim = 2, thenmovemean(A,k,2)从第一行开始,然后在每列中水平滑动。平均计算k一次元素。然后它移至第二行并重复计算。这个过程一直持续到所有行耗尽为止。

数据类型:双倍的|single|int8|int16|INT32|INT64|UINT8|UINT16|uint32|uint64

condition, specified as one of these values:

  • 'includenan'— Includevalues from the input when computing the mean, resulting in输出。

  • 'omitnan'- 忽略所有输入中的值。如果窗口仅包含values, thenmovemeanreturns.

名称值对参数

指定可选的逗号分隔对名称,价值参数。Name是参数名称和Valueis the corresponding value.Namemust appear inside single quotes (' ')。您可以按任何顺序指定几个名称和值对参数Name1,Value1,...,NameN,ValueN.

例子:m = movmean(a,k,'端点','fill')

全部收缩

处理前导和尾随窗户的方法,指定为逗号分隔对'Endpoints'and one of the following:

'Endpoints'Value 描述
'收缩' Shrink the window size near the endpoints of the input to include only existing elements.
'丢弃' Do not output any averages when the window does not completely overlap with existing elements.
'充满' Substitute nonexisting elements with.
numeric or logical scalar Substitute nonexisting elements with a specified numeric or logical value.

数据类型:双倍的|single|int8|int16|INT32|INT64|UINT8|UINT16|uint32|uint64|logical|char|细绳

Sample points for computing averages, specified as the comma-separated pair consisting of'SamplePoints'和矢量。样品点表示数据的位置A. Sample points do not need to be uniformly sampled. By default, the sample points vector is[1 2 3 ...].

Moving windows are defined relative to the sample points, which must be sorted and contain unique elements. For example, ift是对应于输入数据的矢量时间,然后movmean(rand(1,10),3,“样本点”,t)有一个窗口,表示之间的时间间隔t(i)-1.5andt(i)+1.5.

什么时候the sample points vector has data type约会时间or期间, then the moving window length must have type期间.

如果the sample points are nonuniformly spaced and the'Endpoints'name-value pair is specified, then its value must be'收缩'.

数据类型:single|双倍的|int8|int16|INT32|INT64|UINT8|UINT16|uint32|uint64|约会时间|期间

More About

全部收缩

Mean

For a random variable vectorAN标量观察,平均值定义为

μ = 1 N i = 1 N A i .

扩展功能

Introduced in R2016a

这个话题有帮助吗?